From 4823379f422afdffaa0cab21d37fffc3064a850f Mon Sep 17 00:00:00 2001 From: Andrea Fazzi Date: Fri, 31 Jan 2020 15:03:26 +0100 Subject: [PATCH] Encode form values in gen_targets --- benchmarks/gen_targets.go | 17 +++++++++++++---- handlers/handlers.go | 3 +++ orm/response.go | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/benchmarks/gen_targets.go b/benchmarks/gen_targets.go index 2b12f670..e6686da2 100644 --- a/benchmarks/gen_targets.go +++ b/benchmarks/gen_targets.go @@ -1,7 +1,7 @@ package main import ( - "encoding/base64" + "bytes" "encoding/json" "errors" "flag" @@ -9,6 +9,7 @@ import ( "io/ioutil" "log" "net/http" + "net/url" "os" "path" "path/filepath" @@ -63,13 +64,16 @@ func genPOSTResponseTargets(targetName string, conf *config) error { } targets := make([]*vegeta.Target, 0) + form := url.Values{} + form.Set("Singleresponses.0", "32") // payload := "SingleResponses.0=32&SingleResponses.1=68&SingleResponses.2=34&SingleResponses.3=46&SingleResponses.4=25&SingleResponses.5=42&SingleResponses.6=7&SingleResponses.7=38&SingleResponses.8=13&SingleResponses.9=24&SingleResponses.10=73&SingleResponses.11=1&SingleResponses.12=19&SingleResponses.13=64&SingleResponses.14=80&SingleResponses.15=11&SingleResponses.16=70&SingleResponses.17=54&SingleResponses.18=50&SingleResponses.19=57" for i, participant := range participants { targets = append(targets, &vegeta.Target{ Method: "POST", URL: fmt.Sprintf("%s/responses/%d/update?format=html&tpl_content=responses_add_update&tpl_layout=base&update=true&login_session=%s", conf.Url, i+1, tokens[participant.FiscalCode]), - Body: []byte(base64.StdEncoding.EncodeToString([]byte("PUNCH!"))), + // Body: []byte(base64.StdEncoding.EncodeToString([]byte(payload))), + Body: []byte(form.Encode()), Header: http.Header{"Content-Type": []string{"application/x-www-form-urlencoded"}}, }) } @@ -85,11 +89,16 @@ func genPOSTResponseTargets(targetName string, conf *config) error { defer output.Close() for _, t := range targets { - jsonData, err := json.Marshal(t) + var line string + buf := bytes.NewBufferString(line) + encoder := json.NewEncoder(buf) + encoder.SetEscapeHTML(false) + err := encoder.Encode(t) + // jsonData, err := json.Marshal(t) if err != nil { return err } - _, err = output.WriteString(string(jsonData) + "\n\n") + _, err = output.WriteString(buf.String() + "\n\n") if err != nil { return err } diff --git a/handlers/handlers.go b/handlers/handlers.go index 0c84e577..dd25f5cc 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -374,6 +374,9 @@ func respondWithError(h *Handlers, w http.ResponseWriter, r *http.Request, err e if format == "" { format = renderer.GetContentFormat(r) } + if h.Config.LogLevel > config.LOG_LEVEL_OFF { + log.Println(err) + } w.WriteHeader(http.StatusInternalServerError) h.Renderer[format].Render(w, r, h.CookieStore, err) } diff --git a/orm/response.go b/orm/response.go index 84e7dc0f..5881c986 100644 --- a/orm/response.go +++ b/orm/response.go @@ -233,6 +233,7 @@ func (model *Response) Update(db *Database, args map[string]string, w http.Respo return nil, errors.OutOfTime } + log.Println("Body", r.Form) err = renderer.Decode(response, r) if err != nil { return nil, err