Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First-class HTTP header support. HTTP request headers are read into and attached to the gRPC Context. Likewise, response headers can be controlled from within your RPC handler.
This works by capturing the HTTP request headers from Jersey. These headers are given to a gRPC ClientInterceptor which translates these headers into a protocol buffer message (imaginatively named
Headers
). This message is then attached as a Metadata key and sent along with the underlying RPC.A ServerInterceptor extracts this protocol buffer message and writes the headers into the current gRPC
Context
(smart thread-local state).The RPC handler can read the headers (separate from the headers being splatted into the
Metadata
, as is the unfortunate default of the "proxy" mode) and do what it wants with them. ServerInterceptors that run after theHttpHeaderServerInterceptor
can also work with these headers (e.g. extract OAuth tokens, JWT, etc.) to transform those headers into whatever Metadata or Context attachment you like.All headers are available inside the
HttpHeaderContext
, a static utility for working with Context-local state.HttpHeaderContext.requestHeaders()
gives access to the request headers, and there's various setter/clear methods for response headers, e.x.HttpHeaderContext.setResponseHeader("X-Hello", "World")
. Likewise, ServerInterceptors running before theHttpHeaderServerInterceptor
can also set headers. And, just like before, these headers are bundled up into theHeaders
proto and sent to the client (usually in-process) to be set on the outgoing HTTP response.TODO: