Skip to content

Commit 8baa0ee

Browse files
author
Steve Ayers
committed
Update header setting
1 parent 22c4d71 commit 8baa0ee

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

handler.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,13 @@ func NewUnaryHandler[Req, Res any](
8888
mergeNonProtocolHeaders(conn.ResponseTrailer(), info.responseTrailer)
8989
}
9090

91-
// Add response headers/trailers from the response into the conn
92-
mergeNonProtocolHeaders(conn.ResponseHeader(), response.Header())
93-
mergeNonProtocolHeaders(conn.ResponseTrailer(), response.Trailer())
91+
// Add response headers/trailers from the response into the conn if they exist
92+
if len(response.Header()) != 0 {
93+
mergeNonProtocolHeaders(conn.ResponseHeader(), response.Header())
94+
}
95+
if len(response.Trailer()) != 0 {
96+
mergeNonProtocolHeaders(conn.ResponseTrailer(), response.Trailer())
97+
}
9498

9599
return conn.Send(response.Any())
96100
}

0 commit comments

Comments
 (0)