#7185 PUT request with Expect header not properly handled
Bug confirmed in code. Expect header explicitly stripped in miniflare fetch.ts and index.ts. Prevents HTTP 100 Continue protocol handling for proxy use cases.
Remove expect from ignored/restricted headers arrays, test with reproduction repo
Analysis Report
Issue Review: cloudflare/workers-sdk#7185
Summary
PUT requests with Expect: 100-continue header fail in wrangler dev mode because the Expect header is explicitly stripped from requests and 100 Continue responses are not handled correctly by miniflare.
Findings
- Created: 2024-11-07
- Updated: 2025-10-30
- Version: 3.85.0 (Wrangler) → 4.60.0 (Current)
- Component: miniflare (local dev server)
- Labels: bug
- Comments: 0
Key Evidence
No PR fixes this issue - Searched for PRs mentioning #7185, "Expect header", and "100 Continue" - none found.
Not mentioned in changelogs - Issue #7185 is not referenced in wrangler or miniflare changelogs.
Root cause identified in code - The
Expectheader is explicitly stripped in TWO places:packages/miniflare/src/http/fetch.ts:12-const ignored = ["transfer-encoding", "connection", "keep-alive", "expect"];packages/miniflare/src/index.ts:788-794-restrictedUndiciHeadersarray includes"expect"
Reproduction repo available - Reporter provided working reproduction at https://github.com/10io/wrangler-expect-header
Error message confirmed - The reported error matches what would happen when 100 Continue is mishandled:
TypeError: Can't read from request stream after responding with an exception.
Root Cause Analysis
The issue occurs at two levels in miniflare's request handling:
1. Inbound Request Handling (packages/miniflare/src/index.ts:788-794)
const restrictedUndiciHeaders = [
"transfer-encoding",
"connection",
"keep-alive",
"expect", // <-- Expect header stripped here
];
This strips the Expect header before the request reaches the worker.
2. Outbound Fetch Handling (packages/miniflare/src/http/fetch.ts:12)
const ignored = ["transfer-encoding", "connection", "keep-alive", "expect"];
When the worker proxies to the backend, the Expect header is again stripped.
Why this causes the error:
When a client sends Expect: 100-continue:
- The client expects a
100 Continueintermediate response before sending the body - Node.js/undici may automatically handle this, but the miniflare infrastructure doesn't properly coordinate
- workerd interprets an intermediate response as "response sent", so attempting to read the request body fails
Proposed Solution
Option A: Remove expect from ignored headers (Simple but may have side effects)
In packages/miniflare/src/http/fetch.ts:
// Before
const ignored = ["transfer-encoding", "connection", "keep-alive", "expect"];
// After
const ignored = ["transfer-encoding", "connection", "keep-alive"];
In packages/miniflare/src/index.ts:
// Before
const restrictedUndiciHeaders = [
"transfer-encoding",
"connection",
"keep-alive",
"expect",
];
// After
const restrictedUndiciHeaders = [
"transfer-encoding",
"connection",
"keep-alive",
];
Option B: Properly handle 100 Continue (More complex but correct)
The more robust solution would be to:
- Keep the
Expectheader but handle100 Continueresponses properly - Configure undici/Node.js to not auto-respond to
100 Continuewhen proxying - Properly forward the
100 Continueresponse to the client before reading the body
This may require setting expectContinue: true in the undici request options and handling the 'continue' event.
Recommendation
Status: KEEP OPEN
Reasoning: The bug is still present in the codebase. The Expect header is explicitly stripped from both inbound and outbound requests in miniflare, preventing proper handling of HTTP 100 Continue protocol. No PRs have attempted to fix this, and the issue hasn't been triaged or discussed.
Action: This is a valid bug affecting users who proxy requests to backends that use Expect: 100-continue (common with tools like Maven, curl with --upload-file, etc.). A fix should be implemented in miniflare.
Implementation Details
Difficulty: Medium
Justification:
- Simple to remove headers from ignored lists (easy)
- But proper 100 Continue handling requires understanding undici's
expectContinueoption and ensuring the response chain works correctly (medium) - Testing edge cases with different clients and backends (medium)
Files to Modify:
packages/miniflare/src/http/fetch.ts- Removeexpectfromignoredarraypackages/miniflare/src/index.ts- RemoveexpectfromrestrictedUndiciHeadersarray- Potentially add undici configuration for proper
expectContinuehandling
Testing Recommendations:
- Use the reproduction repo: https://github.com/10io/wrangler-expect-header
- Test with
curl -H "Expect: 100-continue" --upload-file <file>through wrangler dev - Test Maven deploy commands through a worker proxy
- Test that workers without proxy behavior aren't affected
- Add unit/integration tests for 100 Continue handling
Suggested Comment
Hi, this issue is still relevant. The
Expectheader is explicitly stripped in miniflare's HTTP handling code in two locations:
packages/miniflare/src/http/fetch.ts(line 12,ignoredarray)packages/miniflare/src/index.ts(line 788-794,restrictedUndiciHeadersarray)This prevents proper HTTP
100 Continueprotocol handling when using wrangler dev to proxy requests to backends that expect this header (like Maven repositories, upload services, etc.).A fix would involve removing
expectfrom these arrays and potentially adding proper undici configuration forexpectContinuehandling.
Notes & Feedback (0)
No notes yet.