diff options
author | Linus Groh <mail@linusgroh.de> | 2022-10-30 14:39:32 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-10-30 20:10:29 +0000 |
commit | cc6eaafe6b59d2ba122cdbee9fd7a1aff35672b8 (patch) | |
tree | 818adba43b9e77a90af118a0060a4653d30666ab /Userland/Libraries/LibWeb/Fetch | |
parent | dcded8d39f08c552ce054bdb8e7eaec22dd810d7 (diff) | |
download | serenity-cc6eaafe6b59d2ba122cdbee9fd7a1aff35672b8.zip |
LibWeb: Implement 'Byte sequence as body' AO
Diffstat (limited to 'Userland/Libraries/LibWeb/Fetch')
-rw-r--r-- | Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp | 9 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h | 2 |
2 files changed, 11 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp index d4b5ded3ec..aa5bbc4c9e 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp @@ -6,6 +6,7 @@ #include <LibJS/Runtime/PromiseCapability.h> #include <LibWeb/Bindings/MainThreadVM.h> +#include <LibWeb/Fetch/BodyInit.h> #include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.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)); } +// 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; +} + } diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h index 3dbe155259..7033e759b9 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h @@ -54,4 +54,6 @@ struct BodyWithType { Optional<ByteBuffer> type; }; +WebIDL::ExceptionOr<Body> byte_sequence_as_body(JS::Realm&, ReadonlyBytes); + } |