Skip to content

Interim-response interceptor leaves fetch() responses without headers #217

Open

Description

@mnot

Requests that use expected_interim_responses get a Response from fetch() with no headers, so the harness can't read Server-Request-Count, Server-Now or anything else the origin sent on the final response.

The CLI builds a dispatcher for those requests with interimResponsesCollectingInterceptor (test-engine/client/utils.mjs) and passes it to fetch() as init.dispatcher (test-engine/client/test.mjs). With the interceptor, the final response's headers are empty. Without it, they're all there.

Reproduction

Against a local test server (npm run server), Node v26.10.0, undici 7.10.0, with a one-request config that has interim_responses: [[102]] and a Cache-Control response header:

with interceptor 200            (no headers)
plain            200 cache-control,client-request-count,connection,content-length,content-type,date,keep-alive,request-numbers,server-base-url,server-now,server-request-count

The same shows up in a CLI run: for interim-102, interim-103, interim-no-header-reuse and interim-not-cached, response.headers is empty on the first response (and on both responses for interim-not-cached), although the server's own record of what it sent includes Cache-Control, Date and Server-Request-Count.

Why it matters

  • resNum is NaN for those responses, so Server-Request-Count can't be used to tell cached from not cached. The tests still produce sensible results today (apache, haproxy and squid pass; others fail on the interim response itself), but only because the checks that read the header happen to land on the right side of NaN. I haven't checked every path.
  • Server-Now is missing, so serverNows[idx] is NaN and date headers in the next request aren't normalised in traces (Show request/response traces when clicking a result #215).
  • Any future assertion on a final response's headers in an interim test would fail or pass for the wrong reason.

Cause

I haven't found it. My guess is that onResponseStart is passed through for the 1xx response as well as the final one, and fetch's handler picks up the headers from the first call (empty for a bare 102) instead of the last. That's a guess; I haven't confirmed it, or whether newer undici versions behave differently.

Possible fixes

  • Only forward the final (statusCode >= 200) onResponseStart to the wrapped handler, and collect the 1xx ones without forwarding them.
  • Check whether undici already exposes interim responses through a supported hook (e.g. an onInformation / onResponseInfo-style callback in the version we pin) and use that instead of intercepting.

Related: #168 is about the interim tests' assertions, not about this.

AI-generated: written by Claude Code while reviewing #215, at Mark Nottingham's request. He hasn't independently reproduced it; the reproduction above was run by Claude Code.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions