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

Support http request header passing #22

Closed
m11y opened this issue Mar 3, 2018 · 8 comments
Closed

Support http request header passing #22

m11y opened this issue Mar 3, 2018 · 8 comments

Comments

@m11y
Copy link
Contributor

m11y commented Mar 3, 2018

  1. We need to pass request header from client to grpc method which currently already support, but it seems that user-agent header is duplicated.
  2. And we also need header set from grpc get passed to client.
@m11y m11y changed the title support http request header passing Support http request header passing Mar 3, 2018
Xorlev added a commit that referenced this issue Mar 7, 2018
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 RPC handlers.

Notable other changes:
 - Switches the Grizzly2 as a test provider, for @context injection.
 - Addition of GrpcJerseyPlatformInterceptors, a utility which will be
   used to automatically add interceptors for future behavior.

Resolves #22
@Xorlev
Copy link
Owner

Xorlev commented Mar 7, 2018

Good news, this was already on my list of things to do. Support for this should land in the next day or two.

@Xorlev Xorlev closed this as completed in 4071e94 Mar 8, 2018
@Xorlev
Copy link
Owner

Xorlev commented Mar 9, 2018

@smartwjw When you have a chance to take it for a spin, I'd love your feedback on it and whether there's any rough edges you encounter. It's not too late to change the API in 0.4.0.

@m11y
Copy link
Contributor Author

m11y commented Mar 9, 2018

@Xorlev Thanks, I will try it soon.

@m11y
Copy link
Contributor Author

m11y commented Mar 12, 2018

@Xorlev Thanks a lot for doing this, but I just wonder why not just pass all the response headers from grpc directly, just like the passing behaivor for request headers?

In my situation, I have a RequestIdInterceptor to generator request id for every request, and If I want to pass generated header to client, I will have to set it twice, once for grpc and another for grpc-jersey custom header, thus caused code duplicate.

It will be great that grpc-jersey acts as more like a reverse proxy, like nginx or envoy.

@Xorlev
Copy link
Owner

Xorlev commented Mar 13, 2018 via email

@Xorlev
Copy link
Owner

Xorlev commented Mar 13, 2018 via email

@m11y
Copy link
Contributor Author

m11y commented Mar 13, 2018

  1. About ASCII-serialization

In my opinion, gRPC is built upon http2, since most header should be ASCII-serializable(we didn't use any header that isn't ASCII-serializable), especially API for mobile app and web browser.

The reason I choose grpc-jersey is that I have implemented a backend service for a mobile app, then an H5 version of this app is demand, so I want to expose the existing service with little effort.

By the way, we put an envoy proxy between the client and our server, so if there is a problem of ASCII-serialization, how is envoy dealing with this?

  1. About internal RPCs

The library may expose some method to set whitelist or backlist headers names.

  1. Double passing

User-Agent double passing is not a big problem, I can handle to easily, it ok for me now.

  1. My own interceptor

I will give it a try.

However, I will suggest that the library supplies the abilities to pass header in both ways, the developers use it at his own discretion.

@Xorlev
Copy link
Owner

Xorlev commented Mar 15, 2018

In my opinion, gRPC is built upon http2

gRPC might be, but grpc-jersey is likely not running on a HTTP/2 native server. grpc-jersey is really a browser-compatible HTTP/1.x<->gRPC translation layer.

By the way, we put an envoy proxy between the client and our server, so if there is a problem of ASCII-serialization, how is envoy dealing with this?

It's a fair point. All headers are actually ASCII encoded (base64'd) during translation to HTTP/2 (but they're renamed, e.x. grpc-jersey-response-headers becomes grpc-jersey-response-headers-bin). If you're passing around protos, (as the HttpHeaderInterceptors do), you definitely wouldn't want to blindly pass that through to callers.

The library may expose some method to set whitelist or backlist headers names.

Yes, it could. Again, I'd rather it be an interceptor that can be layered in if desired. Keep in mind, if you went down this route, you may also need per-method whitelists as your needs may be different based on each RPC.

However, I will suggest that the library supplies the abilities to pass header in both ways, the developers use it at his own discretion.

If you develop an interceptor that does this, I certainly wouldn't turn down a pull request. At the moment I don't have any available time to work on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants