Commit Graph

338 Commits

Author SHA1 Message Date
circl
4e6eb35520 LibWeb/Fetch: Pass error from ResourceLoader into network_error 2024-07-05 15:08:13 -06:00
Jamie Mansfield
fb20326979 LibWeb: Support sending DNT header with requests 2024-07-04 16:42:34 +02:00
circl
1f3285eb04 LibWeb: Restrict fetching file: and resource: URLs to internal pages
They are now blocked on pages which:
- Don't have an opaque origin (should be only user-initiated or about:)
- Aren't other file: pages
- Aren't other resource: pages
2024-06-26 12:15:33 -06:00
Andreas Kling
a3c8e60710 LibWeb: Implement very basic in-memory HTTP caching
This patch adds a simple in-memory HTTP cache to each WebContent
process.

It's currently off by default (turn it on with --enable-http-cache)
since the validation logic is lacking and incomplete.
2024-06-23 09:37:23 +02:00
Andreas Kling
47169db452 LibWeb: Make HTTP response directive parsing more robust 2024-06-23 09:37:23 +02:00
Kenneth Myhra
c51d01bea7 Fetch: Make sure we iterate over HeaderMap's headers()
This fixes a build failure when built with CMake option
'-DENABLE_ALL_THE_DEBUG_MACROS=ON'.
2024-06-09 21:13:25 -04:00
Andreas Kling
e636851481 LibHTTP+RequestServer: Add HTTP::HeaderMap and use for response headers
Instead of using a HashMap<ByteString, ByteString, CaseInsensitive...>
everywhere, we now encapsulate this in a class.

Even better, the new class also allows keeping track of multiple headers
with the same name! This will make it possible for HTTP responses to
actually retain all their headers on the perilous journey from
RequestServer to LibWeb.
2024-06-09 15:34:02 +02:00
Jamie Mansfield
ab6b687d4c LibWeb: Implement "Set request’s referrer policy on redirect" AO 2024-06-07 09:54:19 +02:00
Jamie Mansfield
8542a8b458 LibWeb/Fetch: Update "HTTP-redirect fetch" algorithm to latest spec
The spec and implementation's comments had diverged a little, this
brings them in line :)
2024-06-07 09:54:19 +02:00
Jamie Mansfield
7ce35b75aa LibWeb: Implement should block mixed content response to request 2024-06-07 09:50:30 +02:00
Jamie Mansfield
2159377296 LibWeb: Upgrade mixed requests to potentially trustworthy URLs
(if appropriate)
2024-06-07 09:50:30 +02:00
Jamie Mansfield
8f0d035145 LibWeb: Implement should block mixed content request 2024-06-07 09:50:30 +02:00
Jamie Mansfield
8e062a52a3 LibWeb: Move NetworkPartitionKey into a header
This is used elsewhere, such as the HTMLLinkElement.
2024-06-05 05:42:47 +01:00
Jamie Mansfield
956106c6d8 LibWeb: Add from_string function for request priority 2024-06-05 05:42:47 +01:00
Jamie Mansfield
a419dcbe8b LibWeb/Fetch: Update "HTTP fetch" algorithm to latest spec comments
The spec and implementation's comments had diverged a little, this
brings them in line :)
2024-06-04 07:27:52 +02:00
Jamie Mansfield
295c4ef51a LibWeb/Fetch: Use MimeType in DataURL 2024-06-02 19:55:53 +02:00
Matthew Olsson
9ea6ab0ad4 LibJS+LibWeb: Fix a ton of JS_CELL-like macro issues 2024-05-30 09:29:20 -06:00
Timothy Flynn
6056428cb5 LibWeb: Support unbuffered fetch requests
Supporting unbuffered fetches is actually part of the fetch spec in its
HTTP-network-fetch algorithm. We had previously implemented this method
in a very ad-hoc manner as a simple wrapper around ResourceLoader. This
is still the case, but we now implement a good amount of these steps
according to spec, using ResourceLoader's unbuffered API. The response
data is forwarded through to the fetch response using streams.

This will eventually let us remove the use of ResourceLoader's buffered
API, as all responses should just be streamed this way. The streams spec
then supplies ways to wait for completion, thus allowing fully buffered
responses. However, we have more work to do to make the other parts of
our fetch implementation (namely, Body::fully_read) use streams before
we can do this.
2024-05-26 18:29:24 +02:00
Lucas CHOLLET
b30c361b08 LibWeb/Fetch: Implement logic to process a response from HTTP's cache
Co-Authored-By: Andrew Kaster <akaster@serenityos.org>
2024-05-23 13:25:29 -04:00
Lucas CHOLLET
fcbc6123bb LibWeb/Fetch: Add freshness notion to HTTP::Response
Defined in RFC9111 "HTTP Caching".

Co-Authored-By: Andrew Kaster <akaster@serenityos.org>
2024-05-23 13:25:29 -04:00
Andrew Kaster
c05f296014 LibWeb: Start adding infrastructure for an HTTP Cache 2024-05-23 13:25:29 -04:00
Andrew Kaster
a40b331f39 LibWeb: Update steps of HTTP-network-or-cache-fetch per the latest spec
One step was added since we last visited this AO.
2024-05-23 13:25:29 -04:00
Kenneth Myhra
76418f3ffa LibWeb: Implement the concept incrementally read a body 2024-05-20 16:57:52 -04:00
Kenneth Myhra
50f454fdd5 LibWeb: Enqueue body chunks in Fetch::extract_body()
Co-authored-by: Timothy Flynn <trflynn89@pm.me>
2024-05-20 16:57:52 -04:00
Kenneth Myhra
f119ac1a9d LibWeb: Integrate TransformStream into fetch_response_handover() 2024-05-20 16:57:52 -04:00
Timothy Flynn
b5ba60f1d1 LibWeb: Change Fetch's ProcessBodyError to accept a plain JS value
This callback is meant to be triggered by streams, which does not always
provide a WebIDL::DOMException. Pass a plain value instead. Of all the
users of this callback, only one actually uses the value, and already
converts the DOMException to a plain value.
2024-05-20 16:57:52 -04:00
Jamie Mansfield
3438293e7b LibWeb/Fetch: Share a conditional in fetch response handover
See:
- https://github.com/whatwg/fetch/commit/aaada1f
2024-05-19 16:25:50 +02:00
Jamie Mansfield
951fbb1837 LibWeb/Fetch: Expose a minimised Content-Type to Resource Timing
See:
- https://github.com/whatwg/fetch/commit/931cd06
2024-05-19 16:25:50 +02:00
Jamie Mansfield
08e4cf1f3b LibWeb/Fetch: Implement Body::bytes()
See:
- https://github.com/whatwg/fetch/commit/1085f4f
2024-05-19 16:25:50 +02:00
Shannon Booth
53eb9af42f LibWeb: Use URL's 'blob URL entry' for blob fetches
Performing a lookup in the blob URL registry does not work in the case
of a web worker - as the registry is not shared between processes.
However - the URL itself passed to a worker has the blob attached to it,
which we can pull out of the URL on a fetch.
2024-05-12 15:46:29 -06:00
Jamie Mansfield
74d90338b1 LibWeb/Fetch: Support setting request priority from JS 2024-05-07 17:27:37 -06:00
Jamie Mansfield
4387d12159 LibWeb/Fetch: Block ports 4190 and 6679
See:
- https://github.com/whatwg/fetch/commit/4c3750d
2024-05-07 17:27:37 -06:00
Jamie Mansfield
987198782c LibWeb/Fetch: Use "json" destination
See:
- https://github.com/SerenityOS/serenity/commit/da8d0d8
- https://github.com/whatwg/fetch/commit/49bff76
- https://github.com/whatwg/html/commit/37659e9
2024-05-07 17:27:37 -06:00
Jamie Mansfield
f5799f7d2c LibWeb/Fetch: Append the Fetch metadata headers 2024-05-01 12:57:35 +02:00
Jamie Mansfield
e52f444329 LibWeb/Fetch: Implement the "set the Sec-Fetch-User header" AO 2024-05-01 12:57:35 +02:00
Jamie Mansfield
1ff90aa3e0 LibWeb/Fetch: Implement the "set the Sec-Fetch-Site header" AO 2024-05-01 12:57:35 +02:00
Jamie Mansfield
5eb46a5f01 LibWeb/Fetch: Implement the "set the Sec-Fetch-Mode header" AO 2024-05-01 12:57:35 +02:00
Jamie Mansfield
f4af1833c1 LibWeb/Fetch: Implement the "set the Sec-Fetch-Dest header" AO 2024-05-01 12:57:35 +02:00
Jamie Mansfield
6e3b2ce300 LibWeb/Fetch: Add to_string function for Request::Mode 2024-05-01 12:57:35 +02:00
Jamie Mansfield
3daba8970c LibWeb/Fetch: Add to_string function for Request::Destination 2024-05-01 12:57:35 +02:00
Jamie Mansfield
da8d0d82c0 LibWeb/Fetch: Add "json" destination for JSON modules
This is a change in the Fetch spec.

See:
- https://github.com/whatwg/fetch/commit/49bff76
2024-05-01 12:57:35 +02:00
Timothy Flynn
c29916775e LibWeb: Mark stream AOs as infallible as required by the spec
There were several instances where the spec marks an AO invocation as
infallible, but we were propagating WebIDL::ExceptionOr. These mostly
cannot throw due to knowledge about the values they are provided. By
unwinding these, we can remove a decent amount of exception handling.
2024-04-30 08:14:12 +02:00
Timothy Flynn
34b446ab34 LibWeb: Assign the Content-Type fetch response header as appropriate
The condition here was inverted.
2024-04-28 12:32:04 +02:00
Timothy Flynn
b04ef436fa LibWeb: Remove OOM propagation from Fetch::Response 2024-04-28 12:32:04 +02:00
Timothy Flynn
790589ceb0 LibWeb: Remove OOM propagation from Fetch::Request 2024-04-28 12:32:04 +02:00
Timothy Flynn
d12c560859 LibWeb: Remove OOM propagation from Fetch::Headers 2024-04-28 12:32:04 +02:00
Timothy Flynn
d327fa8135 LibWeb: Remove OOM propagation from Fetch::BodyInit 2024-04-28 12:32:04 +02:00
Timothy Flynn
3e991a55fa LibWeb: Remove OOM propagation from Fetch::Body 2024-04-28 12:32:04 +02:00
Shannon Booth
bad44f8fc9 LibWeb: Remove Bindings/Forward.h from LibWeb/Forward.h
This was resulting in a whole lot of rebuilding whenever a new IDL
interface was added.

Instead, just directly include the prototype in every C++ file which
needs it. While we only really need a forward declaration in each cpp
file; including the full prototype header (which itself only includes
LibJS/Object.h, which is already transitively brought in by
PlatformObject) - it seems like a small price to pay compared to what
feels like a full rebuild of LibWeb whenever a new IDL file is added.

Given all of these includes are only needed for the ::initialize
method, there is probably a smart way of avoiding this problem
altogether. I've considered both using some macro trickery or generating
these functions somehow instead.
2024-04-27 18:29:35 -04:00
Timothy Flynn
c9a461ee75 LibWeb: Remove OOM propagation from Fetch::Infrastructure::HTTP 2024-04-27 07:08:14 +02:00