Skip to content

fix(res.redirect): avoid Content-Length with Transfer-Encoding - #7508

Open
0d00ciallo0721 wants to merge 1 commit into
expressjs:masterfrom
0d00ciallo0721:agent-tasks/7506
Open

0d00ciallo0721 wants to merge 1 commit into
expressjs:masterfrom
0d00ciallo0721:agent-tasks/7506

Conversation

@0d00ciallo0721

Copy link
Copy Markdown

Fixes #7506

res.redirect() currently adds Content-Length even when an application has already set Transfer-Encoding. That produces a response Node's HTTP parser rejects. This change follows the existing res.send() behavior and only sets the length when no Transfer-Encoding header is present.

AI assistance was used to prepare the implementation and regression test.

Verification

  • The regression test failed on the original master with HPE_INVALID_CONTENT_LENGTH and passes with this change.
  • npm test — 1262 passing.
  • npm run lint — passed.
  • Local HTTP checks confirmed HEAD remains bodyless and a 301 redirect preserves its status, Location, and body with chunked transfer encoding.

@0d00ciallo0721
0d00ciallo0721 marked this pull request as ready for review October 6, 2026 08:40

@kgeminicdev kgeminicdev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the reporter of #7506, I can confirm this fixes it. I checked out the branch: test/res.redirect.js passes (14) and the full suite passes (1262). I also tried a case the new test doesn't cover: a HEAD request with Transfer-Encoding: chunked set before res.redirect(301, ...) returns 301 with no Content-Length, Transfer-Encoding intact and Location preserved.

One optional nit: res.send() has a short comment explaining why Content-Length is skipped when Transfer-Encoding is set. The same one-liner here would keep the two in sync for the next reader.

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.

res.redirect() sets Content-Length when Transfer-Encoding is already set

2 participants