Repository navigation
fix(nuxt): read the content type from the node response on h3 v1 - #32
Merged
Merged
Conversation
`getContentType()` only looked at h3 v2's `event.res.headers`. On h3 v1 —
Nitro 2, so Nuxt 3 and 4 — response headers live on the node response, so
in the `beforeResponse` hook the content type set by a handler or by
Nitro's static handler always read as empty. An empty content type counts
as compressible (it usually means an object body), so the `contentTypes`
filter never applied there: images, fonts and other binary public assets
were compressed as well.
It now falls back to `event.node.res.getHeader('content-type')`.
This was referenced Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found while verifying #28–#31 end-to-end in the Nuxt 4.7 playground — no separate issue.
Problem
The module's
contentTypesfilter didn't apply on h3 v1 (Nitro 2 → Nuxt 3 and 4) for anything going through thebeforeResponsehook.getContentType()falls back to the headers already set on the event when the hook hands over no header record — but it only looked at h3 v2'sevent.res.headers. On h3 v1 those headers live on the node response, so the content type that a handler or Nitro's static handler had set always read as empty. An empty content type is deliberately treated as compressible (it usually means an object body that h3 will serialize as JSON), so images, fonts and other binary public assets were compressed too.Observed in the playground:
/favicon.ico(image/vnd.microsoft.icon) came back withContent-Encoding: gzipalthoughimage/*isn't in the defaultcontentTypes.Fix
Fall back to
event.node.res.getHeader('content-type')whenevent.reshas nothing (array values are joined).Tests
getContentType/shouldCompresson a v1-shaped event;image/pngis left untouched (fails onmain),text/cssset the same way is still compressed.End-to-end in the Nuxt 4.7 playground after the fix:
/favicon.icois served unencoded with its originalContent-Length; the SSR page and/api/itemsare still compressed withVary: Accept-Encoding.