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

LibWeb: Move Fetch infra into the Web::Fetch::Infrastructure namespace

The Fetch spec unfortunately will cause a name clash between the Request
concept and the Request JS object - both cannot live in the Web::Fetch
namespace, and WrapperGenerator generally assumes `Web::<Name>` for
things living in the `<Name>/` subdirectory, so let's instead move infra
code into its own namespace - it already sits in a (sub-)subdirectory
anyway.
This commit is contained in:
Linus Groh 2022-07-17 23:52:02 +01:00
parent 4b415a23c1
commit 2726fc9c73
20 changed files with 41 additions and 41 deletions

View file

@ -9,7 +9,7 @@
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <LibWeb/Fetch/Infrastructure/HTTP.h> #include <LibWeb/Fetch/Infrastructure/HTTP.h>
namespace Web::Fetch { namespace Web::Fetch::Infrastructure {
// https://fetch.spec.whatwg.org/#collect-an-http-quoted-string // https://fetch.spec.whatwg.org/#collect-an-http-quoted-string
String collect_an_http_quoted_string(GenericLexer& lexer, HttpQuotedStringExtractValue extract_value) String collect_an_http_quoted_string(GenericLexer& lexer, HttpQuotedStringExtractValue extract_value)

View file

@ -10,7 +10,7 @@
#include <AK/Forward.h> #include <AK/Forward.h>
#include <AK/StringView.h> #include <AK/StringView.h>
namespace Web::Fetch { namespace Web::Fetch::Infrastructure {
// https://fetch.spec.whatwg.org/#http-tab-or-space // https://fetch.spec.whatwg.org/#http-tab-or-space
// An HTTP tab or space is U+0009 TAB or U+0020 SPACE. // An HTTP tab or space is U+0009 TAB or U+0020 SPACE.

View file

@ -6,7 +6,7 @@
#include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h> #include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h>
namespace Web::Fetch { namespace Web::Fetch::Infrastructure {
Body::Body(ReadableStreamDummy stream) Body::Body(ReadableStreamDummy stream)
: m_stream(stream) : m_stream(stream)

View file

@ -13,7 +13,7 @@
#include <AK/Variant.h> #include <AK/Variant.h>
#include <LibWeb/FileAPI/Blob.h> #include <LibWeb/FileAPI/Blob.h>
namespace Web::Fetch { namespace Web::Fetch::Infrastructure {
// https://fetch.spec.whatwg.org/#concept-body // https://fetch.spec.whatwg.org/#concept-body
class Body final { class Body final {

View file

@ -16,7 +16,7 @@
#include <LibWeb/Infra/ByteSequences.h> #include <LibWeb/Infra/ByteSequences.h>
#include <LibWeb/MimeSniff/MimeType.h> #include <LibWeb/MimeSniff/MimeType.h>
namespace Web::Fetch { namespace Web::Fetch::Infrastructure {
template<typename T> template<typename T>
requires(IsSameIgnoringCV<T, u8>) struct CaseInsensitiveBytesTraits : public Traits<Span<T>> { requires(IsSameIgnoringCV<T, u8>) struct CaseInsensitiveBytesTraits : public Traits<Span<T>> {

View file

@ -14,7 +14,7 @@
#include <AK/String.h> #include <AK/String.h>
#include <AK/Vector.h> #include <AK/Vector.h>
namespace Web::Fetch { namespace Web::Fetch::Infrastructure {
// https://fetch.spec.whatwg.org/#concept-header // https://fetch.spec.whatwg.org/#concept-header
// A header is a tuple that consists of a name (a header name) and value (a header value). // A header is a tuple that consists of a name (a header name) and value (a header value).

View file

@ -11,7 +11,7 @@
#include <LibWeb/Fetch/Infrastructure/HTTP/Methods.h> #include <LibWeb/Fetch/Infrastructure/HTTP/Methods.h>
#include <LibWeb/Infra/ByteSequences.h> #include <LibWeb/Infra/ByteSequences.h>
namespace Web::Fetch { namespace Web::Fetch::Infrastructure {
// https://fetch.spec.whatwg.org/#concept-method // https://fetch.spec.whatwg.org/#concept-method
bool is_method(ReadonlyBytes method) bool is_method(ReadonlyBytes method)

View file

@ -8,7 +8,7 @@
#include <AK/Forward.h> #include <AK/Forward.h>
namespace Web::Fetch { namespace Web::Fetch::Infrastructure {
[[nodiscard]] bool is_method(ReadonlyBytes); [[nodiscard]] bool is_method(ReadonlyBytes);
[[nodiscard]] bool is_cors_safelisted_method(ReadonlyBytes); [[nodiscard]] bool is_cors_safelisted_method(ReadonlyBytes);

View file

@ -7,7 +7,7 @@
#include <AK/Array.h> #include <AK/Array.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h> #include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
namespace Web::Fetch { namespace Web::Fetch::Infrastructure {
// https://fetch.spec.whatwg.org/#concept-request-url // https://fetch.spec.whatwg.org/#concept-request-url
AK::URL const& Request::url() const AK::URL const& Request::url() const

View file

@ -20,7 +20,7 @@
#include <LibWeb/HTML/PolicyContainers.h> #include <LibWeb/HTML/PolicyContainers.h>
#include <LibWeb/HTML/Scripting/Environments.h> #include <LibWeb/HTML/Scripting/Environments.h>
namespace Web::Fetch { namespace Web::Fetch::Infrastructure {
// https://fetch.spec.whatwg.org/#concept-request // https://fetch.spec.whatwg.org/#concept-request
class Request final { class Request final {

View file

@ -6,7 +6,7 @@
#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h> #include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>
namespace Web::Fetch { namespace Web::Fetch::Infrastructure {
// https://fetch.spec.whatwg.org/#ref-for-concept-network-error%E2%91%A3 // https://fetch.spec.whatwg.org/#ref-for-concept-network-error%E2%91%A3
// A network error is a response whose status is always 0, status message is always // A network error is a response whose status is always 0, status message is always

View file

@ -16,7 +16,7 @@
#include <LibWeb/Fetch/Infrastructure/HTTP/Headers.h> #include <LibWeb/Fetch/Infrastructure/HTTP/Headers.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Statuses.h> #include <LibWeb/Fetch/Infrastructure/HTTP/Statuses.h>
namespace Web::Fetch { namespace Web::Fetch::Infrastructure {
// https://fetch.spec.whatwg.org/#concept-response // https://fetch.spec.whatwg.org/#concept-response
class Response { class Response {

View file

@ -8,7 +8,7 @@
#include <AK/Array.h> #include <AK/Array.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Statuses.h> #include <LibWeb/Fetch/Infrastructure/HTTP/Statuses.h>
namespace Web::Fetch { namespace Web::Fetch::Infrastructure {
// https://fetch.spec.whatwg.org/#null-body-status // https://fetch.spec.whatwg.org/#null-body-status
bool is_null_body_status(Status status) bool is_null_body_status(Status status)

View file

@ -8,7 +8,7 @@
#include <AK/Forward.h> #include <AK/Forward.h>
namespace Web::Fetch { namespace Web::Fetch::Infrastructure {
// https://fetch.spec.whatwg.org/#concept-status // https://fetch.spec.whatwg.org/#concept-status
// A status is an integer in the range 0 to 999, inclusive. // A status is an integer in the range 0 to 999, inclusive.

View file

@ -6,7 +6,7 @@
#include <LibWeb/Fetch/Infrastructure/URL.h> #include <LibWeb/Fetch/Infrastructure/URL.h>
namespace Web::Fetch { namespace Web::Fetch::Infrastructure {
// https://fetch.spec.whatwg.org/#is-local // https://fetch.spec.whatwg.org/#is-local
bool is_local_url(AK::URL const& url) bool is_local_url(AK::URL const& url)

View file

@ -9,7 +9,7 @@
#include <AK/Array.h> #include <AK/Array.h>
#include <AK/URL.h> #include <AK/URL.h>
namespace Web::Fetch { namespace Web::Fetch::Infrastructure {
// https://fetch.spec.whatwg.org/#local-scheme // https://fetch.spec.whatwg.org/#local-scheme
// A local scheme is "about", "blob", or "data". // A local scheme is "about", "blob", or "data".

View file

@ -170,7 +170,7 @@ namespace Web::Encoding {
class TextEncoder; class TextEncoder;
} }
namespace Web::Fetch { namespace Web::Fetch::Infrastructure {
class Body; class Body;
struct Header; struct Header;
class HeaderList; class HeaderList;

View file

@ -54,7 +54,7 @@ static bool contains_only_http_token_code_points(StringView string)
Optional<MimeType> MimeType::from_string(StringView string) Optional<MimeType> MimeType::from_string(StringView string)
{ {
// 1. Remove any leading and trailing HTTP whitespace from input. // 1. Remove any leading and trailing HTTP whitespace from input.
auto trimmed_string = string.trim(Fetch::HTTP_WHITESPACE, TrimMode::Both); auto trimmed_string = string.trim(Fetch::Infrastructure::HTTP_WHITESPACE, TrimMode::Both);
// 2. Let position be a position variable for input, initially pointing at the start of input. // 2. Let position be a position variable for input, initially pointing at the start of input.
GenericLexer lexer(trimmed_string); GenericLexer lexer(trimmed_string);
@ -77,7 +77,7 @@ Optional<MimeType> MimeType::from_string(StringView string)
auto subtype = lexer.consume_until(';'); auto subtype = lexer.consume_until(';');
// 8. Remove any trailing HTTP whitespace from subtype. // 8. Remove any trailing HTTP whitespace from subtype.
subtype = subtype.trim(Fetch::HTTP_WHITESPACE, TrimMode::Right); subtype = subtype.trim(Fetch::Infrastructure::HTTP_WHITESPACE, TrimMode::Right);
// 9. If subtype is the empty string or does not solely contain HTTP token code points, then return failure. // 9. If subtype is the empty string or does not solely contain HTTP token code points, then return failure.
if (subtype.is_empty() || !contains_only_http_token_code_points(subtype)) if (subtype.is_empty() || !contains_only_http_token_code_points(subtype))
@ -92,7 +92,7 @@ Optional<MimeType> MimeType::from_string(StringView string)
lexer.ignore(1); lexer.ignore(1);
// 2. Collect a sequence of code points that are HTTP whitespace from input given position. // 2. Collect a sequence of code points that are HTTP whitespace from input given position.
lexer.ignore_while(is_any_of(Fetch::HTTP_WHITESPACE)); lexer.ignore_while(is_any_of(Fetch::Infrastructure::HTTP_WHITESPACE));
// 3. Let parameterName be the result of collecting a sequence of code points that are not U+003B (;) or U+003D (=) from input, given position. // 3. Let parameterName be the result of collecting a sequence of code points that are not U+003B (;) or U+003D (=) from input, given position.
auto parameter_name = lexer.consume_until([](char ch) { auto parameter_name = lexer.consume_until([](char ch) {
@ -124,7 +124,7 @@ Optional<MimeType> MimeType::from_string(StringView string)
// 8. If the code point at position within input is U+0022 ("), then: // 8. If the code point at position within input is U+0022 ("), then:
if (lexer.peek() == '"') { if (lexer.peek() == '"') {
// 1. Set parameterValue to the result of collecting an HTTP quoted string from input, given position and the extract-value flag. // 1. Set parameterValue to the result of collecting an HTTP quoted string from input, given position and the extract-value flag.
parameter_value = Fetch::collect_an_http_quoted_string(lexer, Fetch::HttpQuotedStringExtractValue::Yes); parameter_value = Fetch::Infrastructure::collect_an_http_quoted_string(lexer, Fetch::Infrastructure::HttpQuotedStringExtractValue::Yes);
// 2. Collect a sequence of code points that are not U+003B (;) from input, given position. // 2. Collect a sequence of code points that are not U+003B (;) from input, given position.
// NOTE: This uses the predicate version as the ignore_until(char) version will also ignore the ';'. // NOTE: This uses the predicate version as the ignore_until(char) version will also ignore the ';'.
@ -139,7 +139,7 @@ Optional<MimeType> MimeType::from_string(StringView string)
parameter_value = lexer.consume_until(';'); parameter_value = lexer.consume_until(';');
// 2. Remove any trailing HTTP whitespace from parameterValue. // 2. Remove any trailing HTTP whitespace from parameterValue.
parameter_value = parameter_value.trim(Fetch::HTTP_WHITESPACE, TrimMode::Right); parameter_value = parameter_value.trim(Fetch::Infrastructure::HTTP_WHITESPACE, TrimMode::Right);
// 3. If parameterValue is the empty string, then continue. // 3. If parameterValue is the empty string, then continue.
if (parameter_value.is_empty()) if (parameter_value.is_empty())

View file

@ -203,9 +203,9 @@ MimeSniff::MimeType XMLHttpRequest::get_response_mime_type() const
{ {
// 1. Let mimeType be the result of extracting a MIME type from xhrs responses header list. // 1. Let mimeType be the result of extracting a MIME type from xhrs responses header list.
// FIXME: Use an actual HeaderList for XHR headers. // FIXME: Use an actual HeaderList for XHR headers.
Fetch::HeaderList header_list; Fetch::Infrastructure::HeaderList header_list;
for (auto const& entry : m_response_headers) { for (auto const& entry : m_response_headers) {
auto header = Fetch::Header { auto header = Fetch::Infrastructure::Header {
.name = MUST(ByteBuffer::copy(entry.key.bytes())), .name = MUST(ByteBuffer::copy(entry.key.bytes())),
.value = MUST(ByteBuffer::copy(entry.value.bytes())), .value = MUST(ByteBuffer::copy(entry.value.bytes())),
}; };
@ -257,7 +257,7 @@ Optional<StringView> XMLHttpRequest::get_final_encoding() const
// https://fetch.spec.whatwg.org/#concept-header-extract-mime-type // https://fetch.spec.whatwg.org/#concept-header-extract-mime-type
// FIXME: This is not only used by XHR, it is also used for multiple things in Fetch. // FIXME: This is not only used by XHR, it is also used for multiple things in Fetch.
Optional<MimeSniff::MimeType> XMLHttpRequest::extract_mime_type(Fetch::HeaderList const& header_list) const Optional<MimeSniff::MimeType> XMLHttpRequest::extract_mime_type(Fetch::Infrastructure::HeaderList const& header_list) const
{ {
// 1. Let charset be null. // 1. Let charset be null.
Optional<String> charset; Optional<String> charset;
@ -313,13 +313,13 @@ Optional<MimeSniff::MimeType> XMLHttpRequest::extract_mime_type(Fetch::HeaderLis
// https://fetch.spec.whatwg.org/#concept-bodyinit-extract // https://fetch.spec.whatwg.org/#concept-bodyinit-extract
// FIXME: The parameter 'body_init' should be 'typedef (ReadableStream or XMLHttpRequestBodyInit) BodyInit'. For now we just let it be 'XMLHttpRequestBodyInit'. // FIXME: The parameter 'body_init' should be 'typedef (ReadableStream or XMLHttpRequestBodyInit) BodyInit'. For now we just let it be 'XMLHttpRequestBodyInit'.
static Fetch::BodyWithType extract_body(XMLHttpRequestBodyInit const& body_init) static Fetch::Infrastructure::BodyWithType extract_body(XMLHttpRequestBodyInit const& body_init)
{ {
// FIXME: 1. Let stream be object if object is a ReadableStream object. Otherwise, let stream be a new ReadableStream, and set up stream. // FIXME: 1. Let stream be object if object is a ReadableStream object. Otherwise, let stream be a new ReadableStream, and set up stream.
Fetch::Body::ReadableStreamDummy stream {}; Fetch::Infrastructure::Body::ReadableStreamDummy stream {};
// FIXME: 2. Let action be null. // FIXME: 2. Let action be null.
// 3. Let source be null. // 3. Let source be null.
Fetch::Body::SourceType source {}; Fetch::Infrastructure::Body::SourceType source {};
// 4. Let length be null. // 4. Let length be null.
Optional<u64> length {}; Optional<u64> length {};
// 5. Let type be null. // 5. Let type be null.
@ -356,7 +356,7 @@ static Fetch::BodyWithType extract_body(XMLHttpRequestBodyInit const& body_init)
// FIXME: 8. If action is non-null, then run these steps in in parallel: // FIXME: 8. If action is non-null, then run these steps in in parallel:
// 9. Let body be a body whose stream is stream, source is source, and length is length. // 9. Let body be a body whose stream is stream, source is source, and length is length.
auto body = Fetch::Body { move(stream), move(source), move(length) }; auto body = Fetch::Infrastructure::Body { move(stream), move(source), move(length) };
// 10. Return (body, type). // 10. Return (body, type).
return { .body = move(body), .type = move(type) }; return { .body = move(body), .type = move(type) };
} }
@ -376,16 +376,16 @@ DOM::ExceptionOr<void> XMLHttpRequest::set_request_header(String const& name_str
return DOM::InvalidStateError::create("XHR send() flag is already set"); return DOM::InvalidStateError::create("XHR send() flag is already set");
// 3. Normalize value. // 3. Normalize value.
value = MUST(Fetch::normalize_header_value(value)); value = MUST(Fetch::Infrastructure::normalize_header_value(value));
// 4. If name is not a header name or value is not a header value, then throw a "SyntaxError" DOMException. // 4. If name is not a header name or value is not a header value, then throw a "SyntaxError" DOMException.
if (!Fetch::is_header_name(name)) if (!Fetch::Infrastructure::is_header_name(name))
return DOM::SyntaxError::create("Header name contains invalid characters."); return DOM::SyntaxError::create("Header name contains invalid characters.");
if (!Fetch::is_header_value(value)) if (!Fetch::Infrastructure::is_header_value(value))
return DOM::SyntaxError::create("Header value contains invalid characters."); return DOM::SyntaxError::create("Header value contains invalid characters.");
// 5. If name is a forbidden header name, then return. // 5. If name is a forbidden header name, then return.
if (Fetch::is_forbidden_header_name(name)) if (Fetch::Infrastructure::is_forbidden_header_name(name))
return {}; return {};
// 6. Combine (name, value) in thiss author request headers. // 6. Combine (name, value) in thiss author request headers.
@ -423,15 +423,15 @@ DOM::ExceptionOr<void> XMLHttpRequest::open(String const& method_string, String
return DOM::InvalidStateError::create("Invalid state: Responsible document is not fully active."); return DOM::InvalidStateError::create("Invalid state: Responsible document is not fully active.");
// 3. If method is not a method, then throw a "SyntaxError" DOMException. // 3. If method is not a method, then throw a "SyntaxError" DOMException.
if (!Fetch::is_method(method)) if (!Fetch::Infrastructure::is_method(method))
return DOM::SyntaxError::create("An invalid or illegal string was specified."); return DOM::SyntaxError::create("An invalid or illegal string was specified.");
// 4. If method is a forbidden method, then throw a "SecurityError" DOMException. // 4. If method is a forbidden method, then throw a "SecurityError" DOMException.
if (Fetch::is_forbidden_method(method)) if (Fetch::Infrastructure::is_forbidden_method(method))
return DOM::SecurityError::create("Forbidden method, must not be 'CONNECT', 'TRACE', or 'TRACK'"); return DOM::SecurityError::create("Forbidden method, must not be 'CONNECT', 'TRACE', or 'TRACK'");
// 5. Normalize method. // 5. Normalize method.
method = MUST(Fetch::normalize_method(method)); method = MUST(Fetch::Infrastructure::normalize_method(method));
// 6. Let parsedURL be the result of parsing url with settingsObjects API base URL and settingsObjects API URL character encoding. // 6. Let parsedURL be the result of parsing url with settingsObjects API base URL and settingsObjects API URL character encoding.
auto parsed_url = settings_object.api_base_url().complete_url(url); auto parsed_url = settings_object.api_base_url().complete_url(url);
@ -500,7 +500,7 @@ DOM::ExceptionOr<void> XMLHttpRequest::send(Optional<XMLHttpRequestBodyInit> bod
if (m_method.is_one_of("GET"sv, "HEAD"sv)) if (m_method.is_one_of("GET"sv, "HEAD"sv))
body = {}; body = {};
auto body_with_type = body.has_value() ? extract_body(body.value()) : Optional<Fetch::BodyWithType> {}; auto body_with_type = body.has_value() ? extract_body(body.value()) : Optional<Fetch::Infrastructure::BodyWithType> {};
AK::URL request_url = m_window->associated_document().parse_url(m_url.to_string()); AK::URL request_url = m_window->associated_document().parse_url(m_url.to_string());
dbgln("XHR send from {} to {}", m_window->associated_document().url(), request_url); dbgln("XHR send from {} to {}", m_window->associated_document().url(), request_url);

View file

@ -55,7 +55,7 @@ public:
using RefCounted::unref; using RefCounted::unref;
ReadyState ready_state() const { return m_ready_state; }; ReadyState ready_state() const { return m_ready_state; };
Fetch::Status status() const { return m_status; }; Fetch::Infrastructure::Status status() const { return m_status; };
DOM::ExceptionOr<String> response_text() const; DOM::ExceptionOr<String> response_text() const;
DOM::ExceptionOr<JS::Value> response(); DOM::ExceptionOr<JS::Value> response();
Bindings::XMLHttpRequestResponseType response_type() const { return m_response_type; } Bindings::XMLHttpRequestResponseType response_type() const { return m_response_type; }
@ -84,7 +84,7 @@ private:
virtual JS::Object* create_wrapper(JS::GlobalObject&) override; virtual JS::Object* create_wrapper(JS::GlobalObject&) override;
void set_ready_state(ReadyState); void set_ready_state(ReadyState);
void set_status(Fetch::Status status) { m_status = status; } void set_status(Fetch::Infrastructure::Status status) { m_status = status; }
void fire_progress_event(String const&, u64, u64); void fire_progress_event(String const&, u64, u64);
MimeSniff::MimeType get_response_mime_type() const; MimeSniff::MimeType get_response_mime_type() const;
@ -93,14 +93,14 @@ private:
String get_text_response() const; String get_text_response() const;
Optional<MimeSniff::MimeType> extract_mime_type(Fetch::HeaderList const& header_list) const; Optional<MimeSniff::MimeType> extract_mime_type(Fetch::Infrastructure::HeaderList const& header_list) const;
explicit XMLHttpRequest(HTML::Window&); explicit XMLHttpRequest(HTML::Window&);
NonnullRefPtr<HTML::Window> m_window; NonnullRefPtr<HTML::Window> m_window;
ReadyState m_ready_state { ReadyState::Unsent }; ReadyState m_ready_state { ReadyState::Unsent };
Fetch::Status m_status { 0 }; Fetch::Infrastructure::Status m_status { 0 };
bool m_send { false }; bool m_send { false };
u32 m_timeout { 0 }; u32 m_timeout { 0 };