Skip to content

nock@14 use of a fetch() recording that uses gzip compression is missing the headers #2832

@trentm

Description

@trentm

Please avoid duplicates

Reproducible test case

https://github.com/trentm/repro-nock-14-gzip-bug

Nock Version

nock@14.0.0

Node Version

v20.18.1

TypeScript Version

No response

What happened?

I am using nock.back to record and replay HTTP responses for testing. A basic test works for me with fetch() requests.

When I added server-side gzip compression the replayed responses are missing the headers.
The recording looks like this:

[
    {
        "scope": "http://127.0.0.1:3001",
        "method": "GET",
        "path": "/",
        "body": "",
        "status": 200,
        "response": [
            "1f8b0800000000000013ab562ac8cc4b57b2522ac8cf4b57aa0500a67de8f20f000000"
        ],
        "rawHeaders": {
            "connection": "keep-alive",
            "content-encoding": "gzip",
            "content-type": "application/json",
            "date": "Wed, 29 Jan 2025 01:11:24 GMT",
            "keep-alive": "timeout=5",
            "transfer-encoding": "chunked"
        },
        "responseIsBinary": false
    }
]

But the Response object when using that recording looks like this:

res:  Response {
  status: 200,
  statusText: '',
  headers: Headers {},
  body: ReadableStream { locked: false, state: 'readable', supportsBYOB: false },
  bodyUsed: false,
  ok: true,
  redirected: false,
  type: 'default',
  url: 'http://127.0.0.1:3001/'
}

I walk through a working example and the failing case (with code) at: https://github.com/trentm/repro-nock-14-gzip-bug#readme

(I'll click "yes" to contributing below, however, I'm not sure of my available time for digging in. Pointers would be appreciated.)

Would you be interested in contributing a fix?

  • yes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions