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

New API: grpc.ContextServerTransportStream(context.Context) #2016

Closed
skipor opened this issue Apr 21, 2018 · 4 comments
Closed

New API: grpc.ContextServerTransportStream(context.Context) #2016

skipor opened this issue Apr 21, 2018 · 4 comments
Assignees
Labels
P2 Type: Feature New features or improvements in behavior

Comments

@skipor
Copy link

skipor commented Apr 21, 2018

Problem

Needed Header/Trailer sniffing in server interceptor. It could be done by wrapping ServerTransportStream and attaching it to the context using NewContextWithServerTransportStream. But there is no clear API access to existing ServerTransportStream. There is serverTransportStreamFromContext but it's unexported.

Header sniffing ServerTransportStream may call grpc.SetHeader and e.t.c. but it seems as hacky workaround.

@johanbrandhorst
Copy link
Contributor

This API existed before #1904 and was removed.

@skipor
Copy link
Author

skipor commented Apr 21, 2018

That was transport.StreamFromContext(ctx context.Context) (s *transport.Stream, ok bool). It was right desition to remove it, because it was using transport.Stream, but not new grpc.ServerTransportStream

@dfawley
Copy link
Member

dfawley commented Apr 23, 2018

We can export this function, also as a temporary experimental feature, to unbreak you. Note that I intend to redesign interceptors and stats handlers (#1805) in the next month or two, because of several deficiencies in their design.

@jhump
Copy link
Member

jhump commented May 8, 2018

FWIW, I didn't choose to export this function in the original PR because it was not really necessary.

You can access the methods of the ServerTransportStream just using the context in which it is stored, by passing the context into grpc.SetHeader, grpc.SendHeader, and grpc.SetTrailer. The only other method, for the stream name, is indirectly accessible via grpc.MethodNameFromStream (by creating a dummygrpc.ServerStream implementation whose Context method returns the context in question).

While not ideal, it was a way to minimize the exported surface area since it's experimental.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P2 Type: Feature New features or improvements in behavior
Projects
None yet
Development

No branches or pull requests

4 participants