소스 검색

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.
Linus Groh 3 년 전
부모
커밋
2726fc9c73

+ 1 - 1
Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP.cpp

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

+ 1 - 1
Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP.h

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

+ 1 - 1
Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp

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

+ 1 - 1
Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h

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

+ 1 - 1
Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Headers.cpp

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

+ 1 - 1
Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Headers.h

@@ -14,7 +14,7 @@
 #include <AK/String.h>
 #include <AK/Vector.h>
 
-namespace Web::Fetch {
+namespace Web::Fetch::Infrastructure {
 
 // 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).

+ 1 - 1
Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Methods.cpp

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

+ 1 - 1
Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Methods.h

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

+ 1 - 1
Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.cpp

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

+ 1 - 1
Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h

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

+ 1 - 1
Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp

@@ -6,7 +6,7 @@
 
 #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
 // A network error is a response whose status is always 0, status message is always

+ 1 - 1
Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.h

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

+ 1 - 1
Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Statuses.cpp

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

+ 1 - 1
Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Statuses.h

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

+ 1 - 1
Userland/Libraries/LibWeb/Fetch/Infrastructure/URL.cpp

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

+ 1 - 1
Userland/Libraries/LibWeb/Fetch/Infrastructure/URL.h

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

+ 1 - 1
Userland/Libraries/LibWeb/Forward.h

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

+ 5 - 5
Userland/Libraries/LibWeb/MimeSniff/MimeType.cpp

@@ -54,7 +54,7 @@ static bool contains_only_http_token_code_points(StringView string)
 Optional<MimeType> MimeType::from_string(StringView string)
 {
     // 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.
     GenericLexer lexer(trimmed_string);
@@ -77,7 +77,7 @@ Optional<MimeType> MimeType::from_string(StringView string)
     auto subtype = lexer.consume_until(';');
 
     // 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.
     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);
 
         // 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.
         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:
         if (lexer.peek() == '"') {
             // 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.
             // 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(';');
 
             // 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.
             if (parameter_value.is_empty())

+ 15 - 15
Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp

@@ -203,9 +203,9 @@ MimeSniff::MimeType XMLHttpRequest::get_response_mime_type() const
 {
     // 1. Let mimeType be the result of extracting a MIME type from xhr’s response’s header list.
     // FIXME: Use an actual HeaderList for XHR headers.
-    Fetch::HeaderList header_list;
+    Fetch::Infrastructure::HeaderList header_list;
     for (auto const& entry : m_response_headers) {
-        auto header = Fetch::Header {
+        auto header = Fetch::Infrastructure::Header {
             .name = MUST(ByteBuffer::copy(entry.key.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
 // 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.
     Optional<String> charset;
@@ -313,13 +313,13 @@ Optional<MimeSniff::MimeType> XMLHttpRequest::extract_mime_type(Fetch::HeaderLis
 
 // 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'.
-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.
-    Fetch::Body::ReadableStreamDummy stream {};
+    Fetch::Infrastructure::Body::ReadableStreamDummy stream {};
     // FIXME: 2. Let action be null.
     // 3. Let source be null.
-    Fetch::Body::SourceType source {};
+    Fetch::Infrastructure::Body::SourceType source {};
     // 4. Let length be null.
     Optional<u64> length {};
     // 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:
 
     // 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).
     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");
 
     // 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.
-    if (!Fetch::is_header_name(name))
+    if (!Fetch::Infrastructure::is_header_name(name))
         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.");
 
     // 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 {};
 
     // 6. Combine (name, value) in this’s 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.");
 
     // 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.");
 
     // 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'");
 
     // 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 settingsObject’s API base URL and settingsObject’s API URL character encoding.
     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))
         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());
     dbgln("XHR send from {} to {}", m_window->associated_document().url(), request_url);

+ 4 - 4
Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h

@@ -55,7 +55,7 @@ public:
     using RefCounted::unref;
 
     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<JS::Value> response();
     Bindings::XMLHttpRequestResponseType response_type() const { return m_response_type; }
@@ -84,7 +84,7 @@ private:
     virtual JS::Object* create_wrapper(JS::GlobalObject&) override;
 
     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);
 
     MimeSniff::MimeType get_response_mime_type() const;
@@ -93,14 +93,14 @@ private:
 
     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&);
 
     NonnullRefPtr<HTML::Window> m_window;
 
     ReadyState m_ready_state { ReadyState::Unsent };
-    Fetch::Status m_status { 0 };
+    Fetch::Infrastructure::Status m_status { 0 };
     bool m_send { false };
     u32 m_timeout { 0 };