Skip to content

Commit

Permalink
fix: set appropriate headers for SSE requests via POST (wundergraph#637)
Browse files Browse the repository at this point in the history
content-type must be application/json
  • Loading branch information
fiam authored and pvormste committed Oct 17, 2023
1 parent 64da473 commit 8fd0767
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,6 @@ func (h *gqlSSEConnectionHandler) buildGETRequest(ctx context.Context) (*http.Re
req.Header = h.options.Header
}

req.Header.Set("Accept", "text/event-stream")
req.Header.Set("Connection", "keep-alive")
req.Header.Set("Cache-Control", "no-cache")

query := req.URL.Query()
query.Add("query", h.options.Body.Query)

Expand All @@ -259,6 +255,7 @@ func (h *gqlSSEConnectionHandler) buildGETRequest(ctx context.Context) (*http.Re
}

req.URL.RawQuery = query.Encode()
h.setSSEHeaders(req)

return req, nil
}
Expand All @@ -278,9 +275,14 @@ func (h *gqlSSEConnectionHandler) buildPOSTRequest(ctx context.Context) (*http.R
req.Header = h.options.Header
}

req.Header.Set("Content-Type", "application/json")
h.setSSEHeaders(req)
return req, nil
}

// setSSEHeaders sets the headers required for SSE for both GET and POST requests
func (h *gqlSSEConnectionHandler) setSSEHeaders(req *http.Request) {
req.Header.Set("Accept", "text/event-stream")
req.Header.Set("Connection", "keep-alive")
req.Header.Set("Cache-Control", "no-cache")

return req, nil
}

0 comments on commit 8fd0767

Please sign in to comment.