1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:07:35 +00:00

LibWeb: Refactor XHR (almost) exactly to the spec

This makes XHR now rely on Fetch, which allows it to correct send
Origin and Referer headers, CORS-preflight and filtering and many other
goodies.

The main thing that's missing is Streams, which means we can't properly
produce progress events or switch to the Loading ready state.

This also doesn't implement the Document responseType just yet.
This commit is contained in:
Luke Wilde 2023-02-28 18:27:52 +00:00 committed by Linus Groh
parent 90cc45b7ec
commit d036862f2b
11 changed files with 782 additions and 203 deletions

View file

@ -25,4 +25,33 @@ void byte_uppercase(ByteBuffer& bytes)
bytes[i] = to_ascii_uppercase(bytes[i]);
}
// https://infra.spec.whatwg.org/#byte-sequence-starts-with
bool is_prefix_of(ReadonlyBytes potential_prefix, ReadonlyBytes input)
{
// "input starts with potentialPrefix" can be used as a synonym for "potentialPrefix is a prefix of input".
return input.starts_with(potential_prefix);
}
// https://infra.spec.whatwg.org/#byte-less-than
bool is_byte_less_than(ReadonlyBytes a, ReadonlyBytes b)
{
// 1. If b is a prefix of a, then return false.
if (is_prefix_of(b, a))
return false;
// 2. If a is a prefix of b, then return true.
if (is_prefix_of(a, b))
return true;
// 3. Let n be the smallest index such that the nth byte of a is different from the nth byte of b.
// (There has to be such an index, since neither byte sequence is a prefix of the other.)
// 4. If the nth byte of a is less than the nth byte of b, then return true.
// 5. Return false.
for (size_t i = 0; i < a.size(); ++i) {
if (a[i] != b[i])
return a[i] < b[i];
}
VERIFY_NOT_REACHED();
}
}