Compression middleware changes behavior of undefined statusText in writeHead

Open
#254 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
62/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
javascript, node.js
Domain
backend

Research direction

Run the attached reproduction with npm install and node pure-node-compression-test.js, comparing compression middleware with and without compression and with an undefined or string status text. Trace how the middleware handles response.writeHead(200, undefined, {'foo': 'bar'}); done means the headers are set consistently when statusText is undefined.

Written by the indexing model from the issue text.

Description

bug

Environment information

Version: Compression 1.8.1

Platform: MacOS 15.6

Node.js version: 22.15.1

Any other relevant information:

What steps will reproduce the bug?

  1. Setup a node server with the compression middleware. You can also set the filter method to always return false, to ensure it's not doing any compression.
  2. In the response handler, call response.writeHead(200, undefined, {'foo': 'bar'}). The status code and headers are not important. The important part is the undefined status text

Observe how the response headers are not getting set at all.
If you change the status text from undefined to any string, the headers do get set.
If you leave the undefined status text, but remove the compression middleware, the headers do get set.

I've attached a repro case showing this. Just npm install and then run the test with node pure-node-compression-test.js

compression-repro.zip

Dominant language
JavaScript
Stars
2.8k
Forks
254
Avg merge
3d 15h
Merged PRs (30d)
3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from expressjs/compression

All issues in expressjs/compression

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.