From 143581879253fae94fa3b409f6736dda3a115469 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 8c174711bf..365db74c87 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 5ef79e747eb5e8de1241007f15a3af5c04054129 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 c839adf6e9..786edb2bc5 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 a12ffef8b648f711b2fed66f6c6f1b61340924fe 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 2308321287..6814faa007 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, "", " ")