Skip to content

Do compress grpc-web responses#408

Merged
jlizen merged 3 commits into
tower-rs:mainfrom
bouk:except-grpc-web
May 6, 2026
Merged

Do compress grpc-web responses#408
jlizen merged 3 commits into
tower-rs:mainfrom
bouk:except-grpc-web

Conversation

@bouk

@bouk bouk commented Sep 11, 2023

Copy link
Copy Markdown
Contributor

Related: #215

Motivation

grpc-web responses aren't compressed right now, but they should be.

Solution

Add exception for application/grpc-web and change exception filter to use starts_with so we match on any encoding format.

@bouk

bouk commented Mar 25, 2024

Copy link
Copy Markdown
Contributor Author

@jplatte can you take a look at this one?

@jplatte

jplatte commented Apr 7, 2024

Copy link
Copy Markdown
Member

Is there a piece of documentation or article that you can link to for justification / proof that this is the right thing to do? I'm not really familiar with GRPC.

@jlizen jlizen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Change looks good to me, thank you @bouk !

@jplatte To answer your earlier question: native gRPC (application/grpc) has its own compression spec so applying HTTP content-encoding on top would double-compress or break the framing. That's why we skip it in general.

gRPC-web (application/grpc-web, application/grpc-web+proto, etc.) is a different protocol that runs over HTTP/1.1 and thus does not use gRPC's compression framing. It's designed to be treated as a normal HTTP response by intermediaries. Its spec doesn't explicitly specify anything about compression, unfortunately.

But, I found that frameworks like envoy DO respect compression headers for grpc-web. Here you can see both grpc-web and grpc-web+proto explicitly allowlisted in envoy's compression module with values that would match this PR's change:

https://github.com/envoyproxy/envoy/blob/97f4cec040185a6588e3f79a655f2685ae43fcda/source/extensions/filters/http/compressor/compressor_filter.cc#L68-L69

Good enough for me :)

@jlizen jlizen force-pushed the except-grpc-web branch from a207492 to 533c168 Compare May 6, 2026 23:42
@jlizen jlizen merged commit 3962dba into tower-rs:main May 6, 2026
12 checks passed
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.

3 participants