Skip to content

Commit 0f401b2

Browse files
author
Steve Ayers
committed
Feedback
Signed-off-by: Steve Ayers <[email protected]>
1 parent 4af645c commit 0f401b2

File tree

4 files changed

+12
-26
lines changed

4 files changed

+12
-26
lines changed

connect.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,6 @@ func (r *Response[_]) Trailer() http.Header {
287287
return r.trailer
288288
}
289289

290-
// setHeader sets the response header.
291-
func (r *Response[_]) setHeader(header http.Header) {
292-
r.header = header
293-
}
294-
295-
// setTrailer sets the response trailer.
296-
func (r *Response[_]) setTrailer(trailer http.Header) {
297-
r.trailer = trailer
298-
}
299-
300290
// internalOnly implements AnyResponse.
301291
func (r *Response[_]) internalOnly() {}
302292

connect_ext_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func TestCallInfo(t *testing.T) {
107107
assert.True(t, callInfo.Spec().IsClient)
108108
assert.Equal(t, callInfo.Peer().Addr, httptest.DefaultRemoteAddr)
109109
assert.Equal(t, callInfo.ResponseHeader().Values(handlerHeader), []string{headerValue})
110-
assert.Equal(t, callInfo.ResponseHeader().Values(handlerTrailer), []string{trailerValue})
110+
// assert.Equal(t, callInfo.ResponseTrailer().Values(handlerTrailer), []string{trailerValue})
111111
})
112112
})
113113
t.Run("generics_api", func(t *testing.T) {
@@ -157,6 +157,8 @@ func TestCallInfo(t *testing.T) {
157157
assert.Nil(t, stream.Close())
158158
assert.Equal(t, stream.ResponseHeader().Values(handlerHeader), []string{headerValue})
159159
assert.Equal(t, callInfo.ResponseHeader().Values(handlerHeader), []string{headerValue})
160+
// assert.Equal(t, stream.ResponseTrailer().Values(handlerTrailer), []string{trailerValue})
161+
// assert.Equal(t, callInfo.ResponseTrailer().Values(handlerTrailer), []string{trailerValue})
160162
})
161163
})
162164
}

context.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ func (c *callInfo) HTTPMethod() string {
104104
// internalOnly implements CallInfo.
105105
func (c *callInfo) internalOnly() {}
106106

107+
// streamCallInfo is a CallInfo implementation used for streaming RPCs.
107108
type streamCallInfo struct {
108109
conn StreamingHandlerConn
109110
}
@@ -125,7 +126,7 @@ func (c *streamCallInfo) ResponseHeader() http.Header {
125126
}
126127

127128
func (c *streamCallInfo) ResponseTrailer() http.Header {
128-
return c.conn.ResponseHeader()
129+
return c.conn.ResponseTrailer()
129130
}
130131

131132
func (c *streamCallInfo) HTTPMethod() string {

handler.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ func NewUnaryHandler[Req, Res any](
8080
return err
8181
}
8282

83+
// Add response headers/trailers into the context callinfo
84+
mergeNonProtocolHeaders(conn.ResponseHeader(), info.ResponseHeader())
85+
mergeNonProtocolHeaders(conn.ResponseTrailer(), info.ResponseTrailer())
86+
8387
// Add response headers/trailers into the conn
8488
mergeNonProtocolHeaders(conn.ResponseHeader(), response.Header())
8589
mergeNonProtocolHeaders(conn.ResponseTrailer(), response.Trailer())
8690

87-
// Add response headers/trailers into the context callinfo also
88-
mergeNonProtocolHeaders(info.ResponseHeader(), response.Header())
89-
mergeNonProtocolHeaders(info.ResponseTrailer(), response.Trailer())
90-
9191
return conn.Send(response.Any())
9292
}
9393

@@ -118,13 +118,7 @@ func NewUnaryHandlerSimple[Req, Res any](
118118
if err != nil {
119119
return nil, err
120120
}
121-
response := NewResponse(responseMsg)
122-
callInfo, ok := CallInfoFromIncomingContext(ctx)
123-
if ok {
124-
response.setHeader(callInfo.ResponseHeader())
125-
response.setTrailer(callInfo.ResponseTrailer())
126-
}
127-
return response, err
121+
return NewResponse(responseMsg), nil
128122
},
129123
options...,
130124
)
@@ -174,10 +168,9 @@ func NewServerStreamHandler[Req, Res any](
174168
if err != nil {
175169
return err
176170
}
177-
info := &streamCallInfo{
171+
ctx = newIncomingContext(ctx, &streamCallInfo{
178172
conn: conn,
179-
}
180-
ctx = newIncomingContext(ctx, info)
173+
})
181174
return implementation(ctx, req, &ServerStream[Res]{conn: conn})
182175
},
183176
)

0 commit comments

Comments
 (0)