Skip to content

Commit

Permalink
fix duplicate headers on non successful responses (#7403)
Browse files Browse the repository at this point in the history
Signed-off-by: yaron2 <schneider.yaron@live.com>
  • Loading branch information
yaron2 committed Jan 18, 2024
1 parent 4bea838 commit f314b49
Showing 1 changed file with 4 additions and 1 deletion.
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

0 comments on commit f314b49

Please sign in to comment.