Commit Graph

204 Commits

Author SHA1 Message Date
Timothy Flynn
6406a561ef LibWeb: Handover the fetch response's internal body data upon completion
These is a normative change to the Fetch spec. See:
https://github.com/whatwg/fetch/commit/9003266
https://github.com/whatwg/fetch/commit/b5a587b
2023-05-29 17:12:46 +02:00
Andreas Kling
aeffa0d988 LibWeb: Make Fetch::Infrastructure::HeaderList::is_empty() public 2023-05-25 12:53:41 -07:00
0GreenClover0
b4c6cddd96 LibWeb: Handle invalid UTF-8 in Fetch's Body#text() 2023-05-25 06:03:40 -07:00
Andreas Kling
0d82cc8a67 LibWeb: Don't assume response object isn't null in fetch abort algorithm
The callee that we're passing it to expects a GCPtr anyway, so there's
no need to explicitly dereference this.

Fixes a crash when loading https://spotify.com/
2023-05-21 16:19:31 +02:00
Andreas Kling
055dabc123 LibWeb: Fix unsafe capture of stack variables in main_fetch() 2023-05-21 16:01:19 +02:00
Sam Atkins
9c2d496dbe LibWeb: Make processBodyError take an optional exception
Changed here:
018ac19838
2023-05-15 16:28:16 +02:00
Timothy Flynn
cb32bb3502 LibWeb: Add an alias for FetchAlgorithm's consume-body callback argument
This will make it more convenient in places where the Variant would need
to be re-typed outside of this class.
2023-05-12 05:47:36 +02:00
Timothy Flynn
dff0e8a0dc LibWeb: Implement the fetch response's unsafe response AO 2023-05-12 05:47:36 +02:00
Timothy Flynn
e4cb27050a LibWeb: Implement the fetch response is CORS-cross-origin AO 2023-05-12 05:47:36 +02:00
Timothy Flynn
29d90ccf3b LibWeb: Implement the legacy extracting an encoding AO 2023-05-12 05:47:36 +02:00
Matthew Olsson
39d8c8d2a9 LibJS+LibWeb: Add missing visit calls in visit_edges implementations 2023-04-30 06:04:33 +02:00
Matthew Olsson
a3344cab63 LibWeb: Fix incorrect usage of JS::GCPtr 2023-04-30 06:04:33 +02:00
Aliaksandr Kalenik
269c25e1d2 LibWeb/Fetch: Pass recursive=false to manual navigation redirect
Implement ca10f49748

Fixes the issue I found while working on navigation:
https://github.com/whatwg/fetch/issues/1629
2023-04-24 13:38:37 +01:00
Sam Atkins
22e0603bf7 LibWeb: Implement integrity-metadata part of fetch algorithm
Specifically, this makes `<link>` elements with an `integrity` attribute
actually work. Previously, we would load their resource, and then drop
it on the floor without actually using it.

The Subresource Integrity code is in `LibWeb/SRI`, since SRI is the name
of the recommendation spec: https://www.w3.org/TR/SRI/

However, the Fetch spec links to the editor's draft, which varies
significantly from the recommendation, and so that is what the code is
based on and what the spec comments link to:
https://w3c.github.io/webappsec-subresource-integrity/

Fixes #18408
2023-04-21 20:44:47 +01:00
Sam Atkins
6d93e03211 LibWeb+Browser+Ladybird: Use JS::SafeFunction for EventLoop callbacks
This automatically protects captured objects from being GC'd before the
callback runs.
2023-04-21 20:44:47 +01:00
Sam Atkins
955528055c LibWeb: Add FIXME: for new step 6 of Fetch's "main fetch"
This step was added in this commit:
2d78995db8
2023-04-21 20:44:47 +01:00
Timothy Flynn
8d4d01d99a LibWeb: Invent a method to stop an in-progress fetch without errors
The HTMLMediaElement will need to stop fetching processes when its load
algorithm is invoked while a fetch is ongoing. We don't have a way to
really stop the process, due to the way it runs on nested deferred task
invocations. So for now, this swaps the fetch callbacks (e.g. to process
a fetch response) with empty callbacks.
2023-04-20 06:19:41 +02:00
Linus Groh
fd35fc5ba8 LibWeb/Fetch: Fix build error in HeadersIterator::next()
Regressed in d4eaaf9.
2023-04-15 16:49:37 +02:00
MacDue
35612c6a7f AK+Everywhere: Change URL::path() to serialize_path()
This now defaults to serializing the path with percent decoded segments
(which is what all callers expect), but has an option not to. This fixes
`file://` URLs with spaces in their paths.

The name has been changed to serialize_path() path to make it more clear
that this method will generate a new string each call (except for the
cannot_be_a_base_url() case). A few callers have then been updated to
avoid repeatedly calling this function.
2023-04-15 06:37:04 +02:00
Linus Groh
1c165b67ef LibWeb/Streams: Use MUST_OR_THROW_OOM() when creating JS exceptions
This cannot throw unless we OOM.
2023-04-14 16:35:17 +02:00
networkException
9915fa72fb AK+Everywhere: Use Optional for URLParser::parse's base_url parameter 2023-04-11 16:28:20 +02:00
Aliaksandr Kalenik
47f03c3a9a LibWeb/Fetch: Use a basic filtered response for redirect navigations
Match following change in the spec:
8f109835dc
2023-04-09 19:10:45 +02:00
Kenneth Myhra
1120011de4 LibWeb: Add FormData support to XHR
This adds FormData support to XHR so that it can post
multipart/form-data encoded data.
2023-04-05 09:43:52 +01:00
Timothy Flynn
ddb4137ed4 LibWeb: Ensure fetch errors set their response types/codes appropriately
If we fail to set the response type to an error, calling code will think
the fetch was successful. We also should not default to an error code of
200, which would also indicate success.
2023-04-04 22:41:20 +01:00
Andreas Kling
d005b1ad1b LibWeb: Support loading file:// URLs via fetch (through ResourceLoader)
This builds on the existing ad-hoc ResourceLoader code for HTTP fetches
which works for files as well.

This also includes a test that checks that stylesheets loaded with the
"file" URL scheme actually work.
2023-03-22 23:34:32 +00:00
Matthew Olsson
7c0c1c8f49 LibJS+LibWeb: Wrap raw JS::Cell*/& fields in GCPtr/NonnullGCPtr 2023-03-15 08:48:49 +01:00
Andreas Kling
a504ac3e2a Everywhere: Rename equals_ignoring_case => equals_ignoring_ascii_case
Let's make it clear that these functions deal with ASCII case only.
2023-03-10 13:15:44 +01:00
Linus Groh
5cc6b1c4db LibWeb/HTML: Port Window.fetch() to IDL 2023-03-07 23:33:34 +00:00
Luke Wilde
b91b67f4f3 LibWeb/Fetch: Actually check if the response is null in recursive fetch
The condition for checking if there was already a response in recursive
fetch was accidentally flipped, always causing a null deref.

This made redirects crash for example.
2023-03-07 18:42:10 +00:00
Luke Wilde
acd5382924 LibWeb/Fetch: Set length synchronously in extract_body
Since we don't currently have streams, we didn't set length anywhere.
However, this is required by XHR's reliance on Fetch to get the total
number of bytes for the progress events.
2023-03-07 11:51:12 +00:00
Luke Wilde
e557602d34 LibWeb: Fully read body if there is one in fetch response handover
Required by XHR's reliance on Fetch.
2023-03-07 11:51:12 +00:00
Luke Wilde
cfbd0bbe0a LibWeb/Fetch: Implement Header's "extract a length" function
Required by XHR's reliance on Fetch.
2023-03-07 11:51:12 +00:00
Luke Wilde
ccdb1bcc4e LibWeb/Fetch: Implement Body's "fully read" function from the spec
Required by XHR's reliance on Fetch.
2023-03-07 11:51:12 +00:00
Luke Wilde
9acc542059 LibWeb: Propagate Realm instead of VM more through Fetch
This makes Fetch rely less on using main_thread_vm().current_realm(),
which relies on the dummy execution context if no JavaScript is
currently running.
2023-03-07 11:51:12 +00:00
Matthew Olsson
c0b2fa74ac LibWeb: Fix a few const-ness issues 2023-03-06 13:05:43 +00:00
Matthew Olsson
70a2ca7fc0 LibJS: Handle both const and non-const Ts in Handle<T>::create()
Again, the const-ness only really involves Heap-internal metadata, so
the callers shouldn't care about mutations here.
2023-03-06 13:05:43 +00:00
Linus Groh
1032ac2453 LibWeb/Fetch: Store Response error message as a String{,View} variant
The majority of error strings are StringView literals, and it seems
silly to require heap-allocating strings for these.

This idea is stolen from a recent change in fd1fbad :^)
2023-03-03 19:50:36 +00:00
Linus Groh
ad4b4046f4 LibWeb/Fetch: Propagate OOM errors from HeaderList::extract_mime_type() 2023-03-03 11:02:21 +00:00
Linus Groh
2d7ce38ee2 LibWeb/MimeSniff: Port MimeType to new String 2023-03-03 11:02:21 +00:00
Linus Groh
fabea2a6a7 LibWeb/MimeSniff: Rename MimeType::from_string() to MimeType::parse()
This matches the spec's "parse a MIME type".
2023-03-03 11:02:21 +00:00
Linus Groh
11023a3c53 LibWeb/Fetch: Port infrastructure to new String 2023-03-03 09:25:34 +00:00
Linus Groh
7f9ddcf420 LibWeb/Fetch: Port JS interfaces to new String
Since BodyInit and Headers are tightly coupled to both Request and
Response, I chose to do all of them at once instead of introducing a
bunch of temporary conversion glue code.
2023-03-03 09:25:34 +00:00
Kenneth Myhra
9da09e4fd3 LibWeb: Port URL and URLSearchParams to new String 2023-03-01 22:44:20 +00:00
Kenneth Myhra
9a5a8d617d LibWeb: Port IDL implementations Blob and File to new String 2023-02-26 00:27:22 +01:00
Kenneth Myhra
3f50025126 LibWeb: Make factory method of Fetch::Response fallible 2023-02-22 09:55:33 +01:00
Kenneth Myhra
54913adf37 LibWeb: Make factory method of Fetch::Request fallible 2023-02-22 09:55:33 +01:00
Kenneth Myhra
a2381a672d LibWeb: Make factory method of Fetch::HeadersIterator fallible 2023-02-22 09:55:33 +01:00
Sam Atkins
2026ea557e LibWeb: Use is_ascii_case_insensitive_match() where the spec says to 2023-02-19 00:46:47 +01:00
Kenneth Myhra
15917146d3 LibWeb: Make factory method of FileAPI::Blob fallible 2023-02-18 00:52:47 +01:00
Timothy Flynn
88814acbd3 LibJS+Everywhere: Convert JS::Error to String
This includes an Error::create overload to create an Error from a UTF-8
StringView. If creating a String from that view fails, the factory will
return an OOM InternalError instead. VM::throw_completion can also make
use of this overload via its perfect forwarding.
2023-02-17 09:14:23 -05:00