ladybird/Libraries/LibWeb/Fetch/Infrastructure/HTTP
Andreas Kling 37bdcc3488 LibWeb: Support MIME type sniffing for streaming HTTP responses
Previously, when loading a document, we would try to sniff the MIME
type by reading from the response body's source. However, for streaming
HTTP responses, the body source is Empty (the data comes through the
stream instead), so we had no bytes to sniff.

This caused pages like hypr.land (which sends no Content-Type header)
to be misidentified as plain text instead of HTML, since the MIME
sniffing algorithm would receive zero bytes and fall back to the
default type.

The fix captures the first bytes of the response body during fetch,
storing them on the Body object. These bytes are the "resource header"
defined by the MIME Sniffing spec - up to 1445 bytes, which is enough
to identify any MIME type the spec can detect.

Since bytes may arrive asynchronously during streaming, we use a
callback mechanism: if bytes aren't ready yet when load_document()
needs them, it registers a callback that fires once enough bytes have
been captured (or the stream ends).

The flow is:
1. FetchedDataReceiver receives network bytes, buffers them
2. When Body is created, buffered bytes are flushed to Body's sniff
   buffer, and subsequent bytes are appended as they arrive
3. Before calling load_document(), Navigable waits for sniff bytes
4. load_document() passes the bytes to MimeSniff::Resource::sniff()
2026-01-24 15:21:26 +01:00
..
Bodies.cpp LibWeb: Support MIME type sniffing for streaming HTTP responses 2026-01-24 15:21:26 +01:00
Bodies.h LibWeb: Support MIME type sniffing for streaming HTTP responses 2026-01-24 15:21:26 +01:00
CORS.cpp LibHTTP+LibWeb+RequestServer: Move Fetch's HTTP header infra to LibHTTP 2025-11-27 14:57:29 +01:00
CORS.h LibHTTP+LibWeb+RequestServer: Move Fetch's HTTP header infra to LibHTTP 2025-11-27 14:57:29 +01:00
MIME.cpp LibHTTP+LibWeb+RequestServer: Move Fetch's HTTP header infra to LibHTTP 2025-11-27 14:57:29 +01:00
MIME.h LibHTTP+LibWeb+RequestServer: Move Fetch's HTTP header infra to LibHTTP 2025-11-27 14:57:29 +01:00
Requests.cpp LibHTTP+LibWeb: Purge non-fresh entries from the memory cache 2026-01-19 08:02:14 -05:00
Requests.h LibHTTP+LibWeb: Move Infrastructure::Request::CacheMode to LibHTTP 2026-01-22 07:05:06 -05:00
Responses.cpp LibWeb: Do not perform any cache revalidation from WebContent 2026-01-19 08:02:14 -05:00
Responses.h LibWeb: Do not perform any cache revalidation from WebContent 2026-01-19 08:02:14 -05:00
Statuses.cpp Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
Statuses.h LibWeb: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00