Bladeren bron

LibWeb: Implement 'Byte sequence as body' AO

Linus Groh 2 jaren geleden
bovenliggende
commit
cc6eaafe6b

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

@@ -6,6 +6,7 @@
 
 
 #include <LibJS/Runtime/PromiseCapability.h>
 #include <LibJS/Runtime/PromiseCapability.h>
 #include <LibWeb/Bindings/MainThreadVM.h>
 #include <LibWeb/Bindings/MainThreadVM.h>
+#include <LibWeb/Fetch/BodyInit.h>
 #include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h>
 #include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h>
 #include <LibWeb/WebIDL/Promise.h>
 #include <LibWeb/WebIDL/Promise.h>
 
 
@@ -54,4 +55,12 @@ JS::NonnullGCPtr<JS::PromiseCapability> Body::fully_read_as_promise() const
     return WebIDL::create_rejected_promise(realm, JS::InternalError::create(realm, "Reading body isn't fully implemented"sv));
     return WebIDL::create_rejected_promise(realm, JS::InternalError::create(realm, "Reading body isn't fully implemented"sv));
 }
 }
 
 
+// https://fetch.spec.whatwg.org/#byte-sequence-as-a-body
+WebIDL::ExceptionOr<Body> byte_sequence_as_body(JS::Realm& realm, ReadonlyBytes bytes)
+{
+    // To get a byte sequence bytes as a body, return the body of the result of safely extracting bytes.
+    auto [body, _] = TRY(safely_extract_body(realm, bytes));
+    return body;
+}
+
 }
 }

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

@@ -54,4 +54,6 @@ struct BodyWithType {
     Optional<ByteBuffer> type;
     Optional<ByteBuffer> type;
 };
 };
 
 
+WebIDL::ExceptionOr<Body> byte_sequence_as_body(JS::Realm&, ReadonlyBytes);
+
 }
 }