Skip to content

Commit

Permalink
Client.CallServerStream should populate spec and peer of Request (#487)
Browse files Browse the repository at this point in the history
Neither `ServerStream` nor `ServerStreamForClient` include `Spec()` and
`Peer()` methods. This is presumably because the signatures for handlers
and stubs includes a `Request`, which _does_ have these methods.

However, on the client side, when invoking a server stream, these fields
were never populated on the `Request`. They are technically still
accessible via `stream.Conn()`. But since `ClientStream` and
`BidiStream` have methods for these, without making the caller poke into
the underlying conn, it seemed like this was likely not the expected way
to retrieve these attributes.

So this PR simply updates the client-side stub so that calling a
server-stream method _does_ populate the relevant fields of the
`Request`. This provides convenient and consistent access to these
fields for client code.
  • Loading branch information
jhump authored Mar 24, 2023
1 parent 0f85414 commit cb46b44
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ func (c *Client[Req, Res]) CallServerStream(ctx context.Context, request *Reques
return nil, c.err
}
conn := c.newConn(ctx, StreamTypeServer)
request.spec = conn.Spec()
request.peer = conn.Peer()
mergeHeaders(conn.RequestHeader(), request.header)
// Send always returns an io.EOF unless the error is from the client-side.
// We want the user to continue to call Receive in those cases to get the
Expand Down

0 comments on commit cb46b44

Please sign in to comment.