Skip to content

Fall back to application/octet-stream for unknown extensions in route.fulfill(path:) - #400

Open
czj wants to merge 2 commits into
YusukeIwaki:mainfrom
czj:fix-mime-type-fallback
Open

czj wants to merge 2 commits into
YusukeIwaki:mainfrom
czj:fix-mime-type-fallback

Conversation

@czj

@czj czj commented Oct 25, 2026

Copy link
Copy Markdown

Hi again! While working on #399 I noticed that Route#mime_type_for never reaches its fallback: MIME::Types.type_for returns an empty array for an unknown extension, and nil.to_s is "", which is truthy in Ruby. So route.fulfill(path: "payload.unknownext") ends up sending an empty content-type header instead of application/octet-stream.

This PR adds the missing &. and a small spec covering both the known-extension case and the fallback (it fails without the fix, got: "").

It's stacked on top of #399, since both touch the same method: until that one lands, the diff here also shows its commit, so only the last commit (Fall back to application/octet-stream…) is new. Once #399 is merged I'll rebase so this becomes a one-liner. And if you'd rather have it folded into #399, or applied on main directly, just tell me and I'll do it that way.

Thanks again for the gem!


🤖 Generated with Claude Code, but prompted, read, and verified by @czj, a caring human :)

czj and others added 2 commits October 24, 2026 20:48
Route and ScreenshotUtils required 'mime/types' at load time, so every
`require 'playwright'` paid for the whole MIME database even though it
is only consulted by `Route#fulfill(path:)` and by screenshots given a
`path:` without a `type:`.

Requiring it inside those two methods, as playwright.rb already does
for the WebSocket transport, cuts `require 'playwright'` from about
215k to 80k allocated objects and about 3.8 MB of RSS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… type

MIME::Types.type_for returns an empty array for an unknown extension, and
nil.to_s is an empty string, which is truthy: route.fulfill(path:) sent an
empty content-type instead of the intended fallback.
@vercel

vercel Bot commented Oct 25, 2026

Copy link
Copy Markdown

@czj is attempting to deploy a commit to the Yusuke Iwaki's projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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