Jelajahi Sumber

LibWeb/Fetch: Implement changes to priority

This patch updates the priority member of fetch requests to be
an enum. The implementation defined struct previously named Priority
has been renamed to InternalPriority in line with the spec.
networkException 1 tahun lalu
induk
melakukan
d1c1218d42

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

@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
+ * Copyright (c) 2023, networkException <networkexception@serenityos.org>
  *
  * SPDX-License-Identifier: BSD-2-Clause
  */
@@ -150,8 +151,14 @@ public:
         Client,
     };
 
+    enum class Priority {
+        High,
+        Low,
+        Auto
+    };
+
     // Members are implementation-defined
-    struct Priority { };
+    struct InternalPriority { };
 
     using BodyType = Variant<Empty, ByteBuffer, JS::NonnullGCPtr<Body>>;
     using OriginType = Variant<Origin, HTML::Origin>;
@@ -207,8 +214,8 @@ public:
     [[nodiscard]] Optional<Destination> const& destination() const { return m_destination; }
     void set_destination(Optional<Destination> destination) { m_destination = move(destination); }
 
-    [[nodiscard]] Optional<Priority> const& priority() const { return m_priority; }
-    void set_priority(Optional<Priority> priority) { m_priority = move(priority); }
+    [[nodiscard]] Priority const& priority() const { return m_priority; }
+    void set_priority(Priority priority) { m_priority = priority; }
 
     [[nodiscard]] OriginType const& origin() const { return m_origin; }
     void set_origin(OriginType origin) { m_origin = move(origin); }
@@ -387,9 +394,13 @@ private:
     //       those destinations skip service workers.
     Optional<Destination> m_destination;
 
-    // https://fetch.spec.whatwg.org/#concept-request-priority
-    // A request has an associated priority (null or a user-agent-defined object). Unless otherwise stated it is null.
-    Optional<Priority> m_priority;
+    // https://fetch.spec.whatwg.org/#request-priority
+    // A request has an associated priority, which is "high", "low", or "auto". Unless stated otherwise it is "auto".
+    Priority m_priority { Priority::Auto };
+
+    // https://fetch.spec.whatwg.org/#request-internal-priority
+    // A request has an associated internal priority (null or an implementation-defined object). Unless otherwise stated it is null.
+    Optional<InternalPriority> m_internal_priority;
 
     // https://fetch.spec.whatwg.org/#concept-request-origin
     // A request has an associated origin, which is "client" or an origin. Unless stated otherwise it is "client".