fix(microfrontend-template): pass through WebSocket upgrade responses as-is#964
Open
seivad wants to merge 1 commit intocloudflare:mainfrom
Open
fix(microfrontend-template): pass through WebSocket upgrade responses as-is#964seivad wants to merge 1 commit intocloudflare:mainfrom
seivad wants to merge 1 commit intocloudflare:mainfrom
Conversation
… as-is When an upstream service responds with HTTP 101 (WebSocket upgrade), the response must be returned directly without wrapping it in a new Response(). Constructing a new Response() drops the webSocket property that carries the client-side WebSocket object, causing the connection to silently close immediately after appearing to establish. This fix adds an early-return for 101 responses before any header or body processing, restoring WebSocket support for Durable Objects, Agents SDK, PartyKit, and any other WebSocket-based upstream service.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Title:
fix(microfrontend-template): pass through WebSocket upgrade responses as-is
Description
Fixes a bug where WebSocket connections through the microfrontend router would silently fail.
When an upstream service (Durable Objects, Agents SDK, PartyKit, etc.) responds with HTTP 101 (WebSocket upgrade), the response must be returned directly. The existing passthrough path wrapped the response in
new Response(upstreamResp.body, ...), which drops thewebSocketproperty that carries the client-side WebSocket object. The connection appears to establish but immediately closes.The fix adds an early return for
status === 101responses immediately afterupstream.fetch(), before any header or body processing.Checklist
This PR modifies an existing template file only — no new template is being introduced, so the new-template checklist does not apply.
microfrontend-template) is unaffected for all non-WebSocket traffic