Skip to content

Intercepted requests in msw/node are missing Content-Length header #2674

@brianhelba

Description

@brianhelba

Prerequisites

Environment check

  • I'm using the latest msw version
  • I'm using Node.js version 20 or higher

Node.js version

v25.6.1

Reproduction repository

https://github.com/brianhelba/msw-content-length-repro

Reproduction steps

npm install && npm test

Current behavior

request.headers.get('Content-Length') is null in the handler. The Content-Length header is normally calculated by the HTTP transport layer when sending the request, but @mswjs/interceptors intercepts before that point, so the header is never set.

This breaks server-side libraries that validate Content-Length before processing POST bodies.

Expected behavior

When using msw/node, intercepted requests should include a calculated Content-Length header, since handlers simulate server-side processing where this header would always be present. The Content-Length for a string body is straightforward to compute.

Note that MSW already calculates Content-Length on responses (added in v2.2.0 via #1996). The same treatment for request headers would be consistent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds:triageIssues that have not been investigated yet.scope:nodeRelated to MSW running in Node

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions