Workers SDK Issue Reports

← Back to Dashboard

#7185 PUT request with Expect header not properly handled

Recommendation:KEEP OPEN
Difficulty:medium
Reasoning:

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.

Suggested Action:

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

  1. No PR fixes this issue - Searched for PRs mentioning #7185, "Expect header", and "100 Continue" - none found.

  2. Not mentioned in changelogs - Issue #7185 is not referenced in wrangler or miniflare changelogs.

  3. Root cause identified in code - The Expect header 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 - restrictedUndiciHeaders array includes "expect"
  4. Reproduction repo available - Reporter provided working reproduction at https://github.com/10io/wrangler-expect-header

  5. 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:

  1. The client expects a 100 Continue intermediate response before sending the body
  2. Node.js/undici may automatically handle this, but the miniflare infrastructure doesn't properly coordinate
  3. 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:

  1. Keep the Expect header but handle 100 Continue responses properly
  2. Configure undici/Node.js to not auto-respond to 100 Continue when proxying
  3. Properly forward the 100 Continue response 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 expectContinue option and ensuring the response chain works correctly (medium)
  • Testing edge cases with different clients and backends (medium)

Files to Modify:

  1. packages/miniflare/src/http/fetch.ts - Remove expect from ignored array
  2. packages/miniflare/src/index.ts - Remove expect from restrictedUndiciHeaders array
  3. Potentially add undici configuration for proper expectContinue handling

Testing Recommendations:

  1. Use the reproduction repo: https://github.com/10io/wrangler-expect-header
  2. Test with curl -H "Expect: 100-continue" --upload-file <file> through wrangler dev
  3. Test Maven deploy commands through a worker proxy
  4. Test that workers without proxy behavior aren't affected
  5. Add unit/integration tests for 100 Continue handling

Suggested Comment

Hi, this issue is still relevant. The Expect header is explicitly stripped in miniflare's HTTP handling code in two locations:

  • packages/miniflare/src/http/fetch.ts (line 12, ignored array)
  • packages/miniflare/src/index.ts (line 788-794, restrictedUndiciHeaders array)

This prevents proper HTTP 100 Continue protocol 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 expect from these arrays and potentially adding proper undici configuration for expectContinue handling.

Notes & Feedback (0)

No notes yet.

Add Note