Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP: add content-type: application/json header #45

Merged
merged 1 commit into from
Apr 17, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
HTTP: add content-type: application/json header
jpfuentes2 committed Apr 17, 2014

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 2b6ee141cb73871edce2f1530605ffadbc3d0007
1 change: 1 addition & 0 deletions command/agent/http.go
Original file line number Diff line number Diff line change
@@ -125,6 +125,7 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque
goto HAS_ERR
}
resp.Write(buf.Bytes())
resp.Header().Set("Content-Type", "application/json")
}
}
return f
28 changes: 28 additions & 0 deletions command/agent/http_test.go
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import (
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"testing"
"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) {
resp := httptest.NewRecorder()
var b structs.BlockingQuery