Skip to content

Commit 2d7dba0

Browse files
authored
graphql: always set content-type to application/json (ethereum#28417)
--------- Signed-off-by: jsvisa <delweng@gmail.com>
1 parent 4cbca51 commit 2d7dba0

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

graphql/graphql_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ func TestGraphQLBlockSerialization(t *testing.T) {
169169
if tt.code != resp.StatusCode {
170170
t.Errorf("testcase %d %s,\nwrong statuscode, have: %v, want: %v", i, tt.body, resp.StatusCode, tt.code)
171171
}
172+
if ctype := resp.Header.Get("Content-Type"); ctype != "application/json" {
173+
t.Errorf("testcase %d \nwrong Content-Type, have: %v, want: %v", i, ctype, "application/json")
174+
}
172175
}
173176
}
174177

graphql/service.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
7373
}
7474

7575
// Setting this disables gzip compression in package node.
76-
w.Header().Set("transfer-encoding", "identity")
76+
w.Header().Set("Transfer-Encoding", "identity")
7777

7878
// Flush the response. Since we are writing close to the response timeout,
7979
// chunked transfer encoding must be disabled by setting content-length.
80-
w.Header().Set("content-type", "application/json")
81-
w.Header().Set("content-length", strconv.Itoa(len(responseJSON)))
80+
w.Header().Set("Content-Type", "application/json")
81+
w.Header().Set("Content-Length", strconv.Itoa(len(responseJSON)))
8282
w.Write(responseJSON)
8383
if flush, ok := w.(http.Flusher); ok {
8484
flush.Flush()
@@ -97,10 +97,10 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
9797
http.Error(w, err.Error(), http.StatusInternalServerError)
9898
return
9999
}
100+
w.Header().Set("Content-Type", "application/json")
100101
if len(response.Errors) > 0 {
101102
w.WriteHeader(http.StatusBadRequest)
102103
}
103-
w.Header().Set("Content-Type", "application/json")
104104
w.Write(responseJSON)
105105
})
106106
}

0 commit comments

Comments
 (0)