Skip to content

fix(decompress): skip HEAD responses#5564

Merged
mcollina merged 1 commit into
nodejs:mainfrom
Ram-blip:fix/decompress-head-response
Jul 16, 2026
Merged

fix(decompress): skip HEAD responses#5564
mcollina merged 1 commit into
nodejs:mainfrom
Ram-blip:fix/decompress-head-response

Conversation

@Ram-blip

@Ram-blip Ram-blip commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

This relates to...

interceptors.decompress() currently attempts to initialize a decoder for HEAD responses when the server includes a supported Content-Encoding.

Because a valid HEAD response contains no response body, the decoder receives no compressed data and response.body.text() rejects with:

Z_BUF_ERROR: unexpected end of file

The interceptor also removes Content-Encoding and Content-Length, even though those headers describe the corresponding GET representation and are valid metadata on a HEAD response.

Rationale

HTTP HEAD responses must not include response content, but their representation headers describe the response that would have been returned for a corresponding GET.

Undici’s Fetch implementation already skips response decoding for HEAD. The decompression interceptor should do the same rather than creating an empty decoder and removing representation metadata.

Changes

Features

N/A

Bug Fixes

  • Bypass the decompression interceptor for HEAD requests.
  • Preserve Content-Encoding and Content-Length on encoded HEAD responses.
  • Ensure the response body resolves to an empty string instead of rejecting with Z_BUF_ERROR.
  • Add a public API regression test using Client.compose(interceptors.decompress()).

Breaking Changes and Deprecations

None.

Testing

node --test test/interceptors/decompress.js
npm run test:interceptors
npm run lint

Status

Signed-off-by: Ram-blip <ramcruze2000@gmail.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.44%. Comparing base (6010668) to head (8a2a6c6).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5564   +/-   ##
=======================================
  Coverage   93.44%   93.44%           
=======================================
  Files         110      110           
  Lines       37434    37438    +4     
=======================================
+ Hits        34979    34984    +5     
+ Misses       2455     2454    -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mcollina mcollina 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.

lgtm

@mcollina
mcollina merged commit 4910410 into nodejs:main Jul 16, 2026
36 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