Skip to content

fix: remove Content-Length from virtual file StreamingResponse#8928

Merged
dmadisetti merged 1 commit intomainfrom
ms/content-encoding
Mar 30, 2026
Merged

fix: remove Content-Length from virtual file StreamingResponse#8928
dmadisetti merged 1 commit intomainfrom
ms/content-encoding

Conversation

@mscolnick
Copy link
Copy Markdown
Contributor

@mscolnick mscolnick commented Mar 30, 2026

Closes #8917

The @file/ endpoint set Content-Length on a StreamingResponse, mixing length-delimited and chunked framing. Starlette's BaseHTTPMiddleware re-wraps streaming bodies through memory object streams, which can desynchronize the byte count from the declared length for large responses. This caused h11 LocalProtocolError when serving large anywidget ESM bundles (~2MB+).

Fix: drop the Content-Length header so h11 uses chunked transfer encoding instead.

Closes #8917

## Summary

The `@file/` endpoint set `Content-Length` on a `StreamingResponse`, mixing length-delimited and chunked framing. Starlette's `BaseHTTPMiddleware` re-wraps streaming bodies through memory object streams, which can desynchronize the byte count from the declared length for large responses. This caused h11 `LocalProtocolError` when serving large anywidget ESM bundles (~2MB+).

Fix: drop the `Content-Length` header so h11 uses chunked transfer encoding instead.
Copilot AI review requested due to automatic review settings March 30, 2026 17:28
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Mar 30, 2026 5:29pm

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a protocol/framing issue in the server’s virtual file (/@file/) endpoint by ensuring large virtual assets are delivered via streaming without an explicit Content-Length, avoiding h11 LocalProtocolError for large anywidget ESM bundles.

Changes:

  • Remove the Content-Length header from the StreamingResponse returned by virtual_file.
  • Add a regression test asserting that large virtual-file responses do not include Content-Length.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
marimo/_server/api/endpoints/assets.py Stops setting Content-Length on the streaming virtual-file response to avoid h11 framing errors.
tests/_server/api/endpoints/test_assets.py Adds a regression test for large virtual-file streaming responses ensuring Content-Length is not present.

@dmadisetti dmadisetti added the bug Something isn't working label Mar 30, 2026
@dmadisetti dmadisetti merged commit 39ce91b into main Mar 30, 2026
49 of 51 checks passed
@dmadisetti dmadisetti deleted the ms/content-encoding branch March 30, 2026 18:18
@github-actions
Copy link
Copy Markdown

🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.21.2-dev89

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Content-Length mismatch when serving large anywidget ESM bundles

3 participants