Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate headers on non successful responses #7403

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/api/http/directmessaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,16 @@ func (a *api) onDirectMessage(w http.ResponseWriter, r *http.Request) {
// Log with debug level and send the error to the client in the body
log.Debugf("HTTP service invocation failed to complete with error: %v", err)

var headersSet bool

if resp != nil {
resp.Close()

// Set headers if present (if resp is not nil, they haven't been sent already)
headers := resp.Headers()
if len(headers) > 0 {
invokev1.InternalMetadataToHTTPHeader(r.Context(), headers, w.Header().Add)
headersSet = true
}
}

Expand All @@ -270,7 +273,7 @@ func (a *api) onDirectMessage(w http.ResponseWriter, r *http.Request) {
)
switch {
case errors.As(err, &codeErr):
if len(codeErr.headers) > 0 {
if len(codeErr.headers) > 0 && !headersSet {
invokev1.InternalMetadataToHTTPHeader(r.Context(), codeErr.headers, w.Header().Add)
}
respondWithHTTPRawResponse(w, &UniversalHTTPRawResponse{
Expand Down