Skip to content

fix(fetch): body.blob() sets Blob.type from Content-Type header#313

Open
godronus wants to merge 1 commit into
bytecodealliance:mainfrom
godronus:fix/blob-type
Open

fix(fetch): body.blob() sets Blob.type from Content-Type header#313
godronus wants to merge 1 commit into
bytecodealliance:mainfrom
godronus:fix/blob-type

Conversation

@godronus

@godronus godronus commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #311.

When calling body.blob() on a Request or Response, the returned Blob was always created with an empty type, regardless of the Content-Type header on the body. This was uncovered by the WPT pass improvements in #312.

Per the Fetch spec 5.2:

▎ If type is non-null, then set object's type to the result of parse a MIME type with type's value.

This fix reads the Content-Type header from the owning request/response when constructing the Blob in parse_body, extracts the MIME type using the existing extract_mime_type helper, and passes the normalized type through Blob::normalize_type before creating the Blob object.

Changes

  • builtins/web/blob.h / blob.cpp: Promotes normalize_type from a file-local free function to a public static method on Blob, so request-response.cpp can call it without duplication.
  • builtins/web/fetch/request-response.cpp: In parse_body, after constructing the body buffer, looks up the Content-Type header on the owning object, parses the MIME type, normalizes it, and passes it when creating the Blob.
  • tests/wpt-harness/expectations/fetch/api/body/formdata.any.js.json: Updates one previously-failing WPT test to PASS (Consume multipart/form-data headers case-insensitively) — the test was failing because it asserted on the Blob.type value derived from the Content-Type header.

Testing

The fix is covered by the WPT test suite. The Consume multipart/form-data headers case-insensitively test in fetch/api/body/formdata.any.js now passes.

Running WPT test suite after merging Response.clone (#312) creates a new fetch/api/body/mime-type.any.js expectations file. (20 PASS, 0 FAIL)

@godronus godronus marked this pull request as draft June 8, 2026 17:31
@godronus godronus marked this pull request as ready for review June 9, 2026 16:43
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.

body.blob() does not set Blob.type from Content-Type header

1 participant