Skip to content

Fail, don't crash, when an expected request never reaches the origin - #221

Merged
mnot merged 1 commit into
mainfrom
claude/conditional-etag-vary-headers-c15e69
Nov 3, 2026
Merged

mnot merged 1 commit into
mainfrom
claude/conditional-etag-vary-headers-c15e69

Conversation

@mnot

@mnot mnot commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

A run against a cache that ignores Vary reported conditional-etag-vary-headers-mismatch as a TypeError ("Cannot read properties of undefined (reading 'request_headers')") rather than a result.

In checkServerRequests, the expected_request_headers and expected_request_headers_missing blocks read serverRequest.request_headers without checking that the origin saw the request. When the cache answers request 2 from its store, there's no server-side record for it, so the read throws. Only the validating-header path had a guard.

The fix asserts that the request was sent before checking its headers, in both blocks. expected_request_headers_missing fails too, because expecting a header to be absent still implies the request was made.

I considered the not_cached branch, which also dereferences serverRequest, and left it alone: the response-level check at the top of the same function rejects a cached response first, so that line isn't reached in practice.

Verified against a small proxy that caches by URL and ignores Vary. conditional-etag-vary-headers-mismatch now reports request 2 wasn't sent to server; before the change it threw the TypeError. npm run lint and npm test pass. I didn't run the full suite or regenerate any results.

AI-generated (Claude Code), from a session where Mark reported the failure, agreed the semantics for the _missing case, and reviewed the diagnosis. He hasn't reviewed this PR text.

🤖 Generated with Claude Code

…origin

checkServerRequests reads serverRequest.request_headers for
expected_request_headers and expected_request_headers_missing without checking
that the origin saw the request. If the cache answers it from its own store,
serverState has no entry and the check throws a TypeError ("Cannot read
properties of undefined (reading 'request_headers')") instead of reporting a
result.

conditional-etag-vary-headers-mismatch hits this with a cache that ignores
Vary: request 2 is served from cache, so the origin never sees it. Assert that
the request was sent, as the validating-header path already does. Both cases
fail, since expecting a header to be absent still implies a request was made.

Checked against a URL-keyed proxy that ignores Vary: the test now reports
"request 2 wasn't sent to server" rather than the TypeError.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@mnot
mnot merged commit 3735bfb into main Nov 3, 2026
2 checks passed
@mnot
mnot deleted the claude/conditional-etag-vary-headers-c15e69 branch November 3, 2026 07:02
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.

1 participant