Skip to content

Commit 43051ba

Browse files
authored
Merge pull request #27 from yookoala/header
Use "applicaiton/json" as content type in header
2 parents fab5288 + e2b4a68 commit 43051ba

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

handler.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const (
2020

2121
type Handler struct {
2222
Schema *graphql.Schema
23-
23+
2424
pretty bool
2525
}
2626
type RequestOptions struct {
@@ -129,7 +129,9 @@ func (h *Handler) ContextHandler(ctx context.Context, w http.ResponseWriter, r *
129129
}
130130
result := graphql.Do(params)
131131

132-
132+
// use proper JSON Header
133+
w.Header().Add("Content-Type", "application/json")
134+
133135
if h.pretty {
134136
w.WriteHeader(http.StatusOK)
135137
buff, _ := json.MarshalIndent(result, "", "\t")
@@ -138,7 +140,7 @@ func (h *Handler) ContextHandler(ctx context.Context, w http.ResponseWriter, r *
138140
} else {
139141
w.WriteHeader(http.StatusOK)
140142
buff, _ := json.Marshal(result)
141-
143+
142144
w.Write(buff)
143145
}
144146
}

handler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010
"strings"
1111
"testing"
1212

13+
"context"
1314
"github.com/graphql-go/graphql"
1415
"github.com/graphql-go/graphql/testutil"
1516
"github.com/graphql-go/handler"
16-
"context"
1717
)
1818

1919
func decodeResponse(t *testing.T, recorder *httptest.ResponseRecorder) *graphql.Result {

0 commit comments

Comments
 (0)