Skip to content

Commit

Permalink
internal/server/response: Don't re-send headers when streaming
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
  • Loading branch information
stgraber committed Dec 7, 2023
1 parent e0a6bfc commit 3515a79
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions internal/server/response/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ func (r *syncResponse) Render(w http.ResponseWriter) error {
code = http.StatusOK
}

w.WriteHeader(code)
if w.Header().Get("Connection") != "keep-alive" {
w.WriteHeader(code)
}

// Handle plain text responses.
if r.plaintext {
Expand Down Expand Up @@ -347,7 +349,9 @@ func (r *errorResponse) Render(w http.ResponseWriter) error {
w.Header().Set("Content-Type", "application/json")
w.Header().Set("X-Content-Type-Options", "nosniff")

w.WriteHeader(r.code) // Set the error code in the HTTP header response.
if w.Header().Get("Connection") != "keep-alive" {
w.WriteHeader(r.code) // Set the error code in the HTTP header response.
}

_, err = fmt.Fprintln(w, buf.String())

Expand Down Expand Up @@ -524,7 +528,10 @@ func (r *forwardedResponse) Render(w http.ResponseWriter) error {
w.Header().Set(key, response.Header.Get(key))
}

w.WriteHeader(response.StatusCode)
if w.Header().Get("Connection") != "keep-alive" {
w.WriteHeader(response.StatusCode)
}

_, err = io.Copy(w, response.Body)
return err
}
Expand Down

0 comments on commit 3515a79

Please sign in to comment.