From 8beb1bb848c24575331f8f01e9aa3863d55dae03 Mon Sep 17 00:00:00 2001 From: Thordur Bjornsson Date: Thu, 1 Jan 2015 15:33:33 +0100 Subject: [PATCH 1/3] handle ?pretty similarly to ?stale, ?consistent etc. --- command/agent/http.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From cb32b82b378d951ac8fe87e02b765a3a07711ec3 Mon Sep 17 00:00:00 2001 From: Thordur Bjornsson Date: Thu, 1 Jan 2015 15:34:59 +0100 Subject: [PATCH 2/3] Revert "correct the doc for obtaining formatted json" This reverts commit cf3b9ec4fee09075481fd5c521dd6c4b8db58e91. --- website/source/docs/agent/http.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 59d4f20e621d84ce8858bb174720a343f9f13b01 Mon Sep 17 00:00:00 2001 From: Thordur Bjornsson Date: Fri, 2 Jan 2015 09:14:44 +0100 Subject: [PATCH 3/3] Test both ?pretty both bare and with value. --- command/agent/http_test.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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, "", " ")