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

Add the "grpc-encoding" header to the response #20

Merged
merged 2 commits into from Mar 25, 2020

Conversation

cb372
Copy link

@cb372 cb372 commented Mar 21, 2020

Once the per-message compression encoding has been negotiated (by
inspecting the grpc-accept-encoding request header), the server should
tell the client the chosen encoding (either identity or gzip) by
setting the grpc-encoding response header.

The meaning of the header is: if any message in the response has its
compression flag set, then that message has been compressed using this
encoding.

Some clients can live with the header being missing. If they encounter a
message with its compression flag set, they just assume the encoding is
GZip. But other clients, notably the official Java gRPC library, are
stricter and require the header to be present.

Aside: compression can be done at the stream level rather than the
individual message level. In that case, the content-encoding header
must be set, and the grpc-encoding header must not be set.

None of this is really documented anywhere. I worked it out using
Wireshark and reading the grpc-java source.

Once the per-message compression encoding has been negotiated (by
inspecting the `grpc-accept-encoding` request header), the server should
tell the client the chosen encoding (either `identity` or `gzip`) by
setting the `grpc-encoding` response header.

The meaning of the header is: if any message in the response has its
compression flag set, then that message has been compressed using this
encoding.

Some clients can live with the header being missing. If they encounter a
message with its compression flag set, they just assume the encoding is
GZip. But other clients, notably the official Java gRPC library, are
stricter and require the header to be present.

Aside: compression can be done at the stream level rather than the
individual message level. In that case, the `content-encoding` header
must be set, and the `grpc-encoding` header must *not* be set.

None of this is really documented anywhere. I worked it out using
Wireshark and reading the [grpc-java
source](https://github.com/grpc/grpc-java/blob/8d4240f4800f20de0e5f0b7c213577b3c0324f93/core/src/main/java/io/grpc/internal/AbstractClientStream.java#L313-L356).
putStrLn "running handler"
_ <- handler pickedDecompression pickedCompression req write flush
_ <- handler (pickedDecompression req) (pickedCompression req) req write flush
putStrLn "setting GRPC status"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind if I delete these putStrLns while I’m here?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do so, I think they should not be there in any case

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link

@serras serras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@serras serras merged commit 91713cf into haskell-grpc-native:master Mar 25, 2020
@serras
Copy link

serras commented Mar 25, 2020

Thanks for the PR! I've just release version 0.4.0.1 with this fix 😄

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

Successfully merging this pull request may close these issues.

None yet

2 participants