mirror of
https://gitlab.com/pulsechaincom/go-pulse.git
synced 2024-12-22 03:30:35 +00:00
graphql: always set content-type to application/json (#28417)
--------- Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
4cbca5178a
commit
2d7dba024d
@ -169,6 +169,9 @@ func TestGraphQLBlockSerialization(t *testing.T) {
|
|||||||
if tt.code != resp.StatusCode {
|
if tt.code != resp.StatusCode {
|
||||||
t.Errorf("testcase %d %s,\nwrong statuscode, have: %v, want: %v", i, tt.body, resp.StatusCode, tt.code)
|
t.Errorf("testcase %d %s,\nwrong statuscode, have: %v, want: %v", i, tt.body, resp.StatusCode, tt.code)
|
||||||
}
|
}
|
||||||
|
if ctype := resp.Header.Get("Content-Type"); ctype != "application/json" {
|
||||||
|
t.Errorf("testcase %d \nwrong Content-Type, have: %v, want: %v", i, ctype, "application/json")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,12 +73,12 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Setting this disables gzip compression in package node.
|
// Setting this disables gzip compression in package node.
|
||||||
w.Header().Set("transfer-encoding", "identity")
|
w.Header().Set("Transfer-Encoding", "identity")
|
||||||
|
|
||||||
// Flush the response. Since we are writing close to the response timeout,
|
// Flush the response. Since we are writing close to the response timeout,
|
||||||
// chunked transfer encoding must be disabled by setting content-length.
|
// chunked transfer encoding must be disabled by setting content-length.
|
||||||
w.Header().Set("content-type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Header().Set("content-length", strconv.Itoa(len(responseJSON)))
|
w.Header().Set("Content-Length", strconv.Itoa(len(responseJSON)))
|
||||||
w.Write(responseJSON)
|
w.Write(responseJSON)
|
||||||
if flush, ok := w.(http.Flusher); ok {
|
if flush, ok := w.(http.Flusher); ok {
|
||||||
flush.Flush()
|
flush.Flush()
|
||||||
@ -97,10 +97,10 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
if len(response.Errors) > 0 {
|
if len(response.Errors) > 0 {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
w.Write(responseJSON)
|
w.Write(responseJSON)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user