Skip to content

Commit

Permalink
parse query params
Browse files Browse the repository at this point in the history
  • Loading branch information
cooldarkdryplace committed May 6, 2018
1 parent 2d3cde4 commit 30dc1e7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion debugserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"log"
"net"
"net/http"
"net/url"
"strings"
)

Expand Down Expand Up @@ -69,6 +70,11 @@ func record(w http.ResponseWriter, r *http.Request) {
log.Printf("Failed to sptil remote address to IP and Port: %s", err)
}

params, err := url.ParseQuery(r.URL.RawQuery)
if err != nil {
http.Error(w, "bad query params", http.StatusBadRequest)
}

bodyReader := http.MaxBytesReader(w, r.Body, 1<<20)
defer bodyReader.Close()
var body bytes.Buffer
Expand All @@ -81,7 +87,7 @@ func record(w http.ResponseWriter, r *http.Request) {
storage.Add(id, Request{
RemoteIP: ip,
URL: r.URL.Path,
QueryParams: r.URL.RawQuery,
QueryParams: params.Encode(),
Method: r.Method,
Headers: r.Header,
Body: base64.StdEncoding.EncodeToString(body.Bytes()),
Expand Down

0 comments on commit 30dc1e7

Please sign in to comment.