Skip to content

fix(ext/http): apply automatic compression for zero-arg serve handlers#35490

Merged
nathanwhit merged 1 commit into
denoland:mainfrom
nathanwhit:fix/serve-zero-arg-compression
Jun 25, 2026
Merged

fix(ext/http): apply automatic compression for zero-arg serve handlers#35490
nathanwhit merged 1 commit into
denoland:mainfrom
nathanwhit:fix/serve-zero-arg-compression

Conversation

@nathanwhit

Copy link
Copy Markdown
Member

A Deno.serve handler that takes zero arguments uses the native "no
request" fast path, where the Request object is never materialized for JS.
On that path the HTTP/1.1 server discarded all request headers
(RawRequestHeaders::empty()), but automatic compression is decided by reading
accept-encoding from the stored request headers. With the headers gone,
raw_request_compression always returned Compression::None, so responses
from zero-arg handlers were never compressed — even when the client supported
gzip/brotli and the body was compressible.

This retains just the accept-encoding header on the fast path (when automatic
compression is enabled), so the compression decision works while still avoiding
the full request-header copy / Request materialization. When automatic
compression is disabled, the headers are still skipped entirely as before.

Repro

// zero-arg handler -> native fast path
Deno.serve(() => new Response("compress me ".repeat(200)));
$ curl -s -H 'accept-encoding: gzip, br' -D - localhost:PORT -o /dev/null
# before: no content-encoding
# after:  content-encoding: br

Tests

The existing httpServerAutomaticCompressionSkippedForNoRequestFastPath test
actually encoded the bug (it asserted compression was skipped). It's rewritten
as httpServerAutomaticCompressionAppliesForNoRequestFastPath, asserting
content-encoding: gzip and vary: Accept-Encoding. The automaticCompression: false tests continue to assert no compression.

A serve handler that takes no arguments uses the native "no request" fast
path, where the Request is never materialized for JS. On that path the H1
server discarded all request headers, but automatic compression is decided
by reading `accept-encoding` from the stored request headers. With the
headers gone, compression was always skipped for zero-arg handlers.

Retain just the `accept-encoding` header on the fast path (when automatic
compression is enabled) so responses are compressed as they are for
handlers that take a Request.
@nathanwhit
nathanwhit merged commit 250b584 into denoland:main Jun 25, 2026
136 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.

1 participant