diff --git a/command/agent/http.go b/command/agent/http.go index 8c174711b..365db74c8 100644 --- a/command/agent/http.go +++ b/command/agent/http.go @@ -253,7 +253,7 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque } prettyPrint := false - if req.URL.Query().Get("pretty") != "" { + if _, ok := req.URL.Query()["pretty"]; ok { prettyPrint = true } // Write out the JSON object diff --git a/command/agent/http_test.go b/command/agent/http_test.go index 230832128..6814faa00 100644 --- a/command/agent/http_test.go +++ b/command/agent/http_test.go @@ -127,6 +127,14 @@ func TestContentTypeIsJSON(t *testing.T) { } func TestPrettyPrint(t *testing.T) { + testPrettyPrint("pretty=1", t) +} + +func TestPrettyPrintBare(t *testing.T) { + testPrettyPrint("pretty", t) +} + +func testPrettyPrint(pretty string, t *testing.T) { dir, srv := makeHTTPServer(t) defer os.RemoveAll(dir) defer srv.Shutdown() @@ -139,7 +147,8 @@ func TestPrettyPrint(t *testing.T) { return r, nil } - req, _ := http.NewRequest("GET", "/v1/kv/key?pretty=1", nil) + urlStr := "/v1/kv/key?" + pretty + req, _ := http.NewRequest("GET", urlStr, nil) srv.wrap(handler)(resp, req) expected, _ := json.MarshalIndent(r, "", " ") diff --git a/website/source/docs/agent/http.html.markdown b/website/source/docs/agent/http.html.markdown index c839adf6e..786edb2bc 100644 --- a/website/source/docs/agent/http.html.markdown +++ b/website/source/docs/agent/http.html.markdown @@ -86,7 +86,7 @@ leader. These can be used to gauge if a stale read should be used. ## Formatted JSON Output By default, the output of all HTTP API requests return minimized JSON with all -whitespace removed. By adding "?pretty=1" to the HTTP request URL, +whitespace removed. By adding "?pretty" to the HTTP request URL, formatted JSON will be returned. ## ACLs