HTTP: add content-type: application/json header
This commit is contained in:
parent
07b7c2227f
commit
e83f723a66
|
@ -125,6 +125,7 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque
|
||||||
goto HAS_ERR
|
goto HAS_ERR
|
||||||
}
|
}
|
||||||
resp.Write(buf.Bytes())
|
resp.Write(buf.Bytes())
|
||||||
|
resp.Header().Set("Content-Type", "application/json")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return f
|
return f
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -39,6 +40,33 @@ func TestSetIndex(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContentTypeIsJSON(t *testing.T) {
|
||||||
|
dir, srv := makeHTTPServer(t)
|
||||||
|
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
defer srv.Shutdown()
|
||||||
|
defer srv.agent.Shutdown()
|
||||||
|
|
||||||
|
// Wait for a leader
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
|
||||||
|
resp := httptest.NewRecorder()
|
||||||
|
|
||||||
|
handler := func(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||||
|
// stub out a DirEntry so that it will be encoded as JSON
|
||||||
|
return &structs.DirEntry{Key: "key"}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
req, _ := http.NewRequest("GET", "/v1/kv/key", nil)
|
||||||
|
srv.wrap(handler)(resp, req)
|
||||||
|
|
||||||
|
contentType := resp.Header().Get("Content-Type")
|
||||||
|
|
||||||
|
if contentType != "application/json" {
|
||||||
|
t.Fatalf("Content-Type header was not 'application/json'")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestParseWait(t *testing.T) {
|
func TestParseWait(t *testing.T) {
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
var b structs.BlockingQuery
|
var b structs.BlockingQuery
|
||||||
|
|
Loading…
Reference in New Issue