tonic icon indicating copy to clipboard operation
tonic copied to clipboard

Add compression support for tonic-web requests

Open BenShelton opened this issue 7 months ago • 1 comments

Feature Request

Crates

tonic-web

Motivation

We currently have endpoints that return a lot of data, however when using tonic-web, even though the service itself is configured to use Gzip compression the actual response is not compressed. Given the following snippet:

let svc = SvcServer::new(Svc::new(settings))
    .send_compressed(CompressionEncoding::Gzip)
    .accept_compressed(CompressionEncoding::Gzip);

  Server::builder()
    .accept_http1(true)
    .add_service(health_service)
    .add_service(reflection)
    .add_service(tonic_web::enable(svc))
    .serve(addr)
    .await?;

A browser request will include accept-encoding: gzip, deflate but the response is always transfer-encoding: chunked. The size of the response is also unchanged between enabling/disabling gzip.

I'm assuming this is a limitation with how tonic-web works and hoping this is something that can be implemented there.

Proposal

Unsure whether this is possible, but adding compression logic into tonic-web the same as exists in the base tonic compression file.

Alternatives

None that I am aware of.

BenShelton avatar May 12 '25 16:05 BenShelton

I think its important that we check if the grpc-web spec supports compression and maybe take a look at the proxies that implement the spec to see how they handle compression.

LucioFranco avatar May 15 '25 07:05 LucioFranco