Merge pull request #567 from thorduri/master
?pretty, work without value.
This commit is contained in:
commit
446692df1a
|
@ -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
|
||||
|
|
|
@ -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, "", " ")
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue