agent: parse raw query URL to avoid closing the request body early

This commit is contained in:
Ryan Uber 2015-04-13 17:31:53 -07:00
parent 26f03ea30d
commit 507917748a
1 changed files with 8 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import (
"net"
"net/http"
"net/http/pprof"
"net/url"
"os"
"strconv"
"strings"
@ -283,9 +284,14 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque
setHeaders(resp, s.agent.config.HTTPAPIResponseHeaders)
// Obfuscate any tokens from appearing in the logs
req.ParseForm()
formVals, err := url.ParseQuery(req.URL.RawQuery)
if err != nil {
s.logger.Printf("[ERR] http: Failed to decode query: %s", err)
resp.WriteHeader(500)
return
}
logURL := req.URL.String()
if tokens, ok := req.Form["token"]; ok {
if tokens, ok := formVals["token"]; ok {
for _, token := range tokens {
logURL = strings.Replace(logURL, token, "<hidden>", -1)
}