diff --git a/graphql/handler/transport/http_post.go b/graphql/handler/transport/http_post.go index 985f8db2941..085f60a910f 100644 --- a/graphql/handler/transport/http_post.go +++ b/graphql/handler/transport/http_post.go @@ -27,6 +27,10 @@ func (h POST) Supports(r *http.Request) bool { return false } + if strings.Contains(r.Header.Get("Accept"), "text/event-stream") { + return false + } + mediaType, _, err := mime.ParseMediaType(r.Header.Get("Content-Type")) if err != nil { return false diff --git a/graphql/handler/transport/http_post_test.go b/graphql/handler/transport/http_post_test.go index 97ef3be6686..28095d856bc 100644 --- a/graphql/handler/transport/http_post_test.go +++ b/graphql/handler/transport/http_post_test.go @@ -96,6 +96,22 @@ func TestPOST(t *testing.T) { }) } }) + + t.Run("validate SSE", func(t *testing.T) { + doReq := func(handler http.Handler, method string, target string, body string) *httptest.ResponseRecorder { + r := httptest.NewRequest(method, target, strings.NewReader(body)) + r.Header.Set("Content-Type", "application/json") + r.Header.Set("Accept", "text/event-stream") + w := httptest.NewRecorder() + + handler.ServeHTTP(w, r) + return w + } + + resp := doReq(h, "POST", "/graphql", `{"query":"{ name }"}`) + assert.Equal(t, http.StatusBadRequest, resp.Code, resp.Body.String()) + assert.Equal(t, `{"errors":[{"message":"transport not supported"}],"data":null}`, resp.Body.String()) + }) } func doRequest(handler http.Handler, method, target, body, contentType string) *httptest.ResponseRecorder {