Bug 270975 - Add ability to sniff media content should we failed to retrieve the content-type
Summary: Add ability to sniff media content should we failed to retrieve the content-type
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Jean-Yves Avenard [:jya]
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2024-03-14 06:41 PDT by Jean-Yves Avenard [:jya]
Modified: 2024-04-15 04:10 PDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jean-Yves Avenard [:jya] 2024-03-14 06:41:12 PDT
We currently rely on the server to provide a valid content-type and if that fails we always use the URL's file name extension instead.

The HTML5 specs clearly states that the type of a resource should be determined through sniffing [1]

And that sniffing should take precedence over the supplied mime type [2].
Parsing the resource header [3] doing 
```
2. Read bytes of the resource into buffer until one of the following conditions is met:
  * the end of the resource is reached.
  * the number of bytes in buffer is greater than or equal to 1445.
  * a reasonable amount of time has elapsed, as determined by the user agent.
```

For now we will only rely on sniffing should the previous way of determining the content-type failed.

[1] https://html.spec.whatwg.org/#content-type-sniffing
[2] https://mimesniff.spec.whatwg.org/#rules-for-sniffing-audio-and-video-specifically
[3] https://mimesniff.spec.whatwg.org/#reading-the-resource-header
Comment 1 Radar WebKit Bug Importer 2024-03-14 06:41:24 PDT
<rdar://problem/124614908>
Comment 2 Jean-Yves Avenard [:jya] 2024-03-14 07:09:23 PDT
Pull request: https://github.com/WebKit/WebKit/pull/25883
Comment 3 EWS 2024-03-18 02:21:21 PDT
Committed 276258@main (93f6303ff83e): <https://commits.webkit.org/276258@main>

Reviewed commits have been landed. Closing PR #25883 and removing active labels.
Comment 4 Jean-Yves Avenard [:jya] 2024-04-15 04:10:04 PDT
likely the same as bug 245428