From cc6eaafe6b59d2ba122cdbee9fd7a1aff35672b8 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 30 Oct 2022 14:39:32 +0000 Subject: [PATCH] LibWeb: Implement 'Byte sequence as body' AO --- .../LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp | 9 +++++++++ .../Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp index d4b5ded3ecd..aa5bbc4c9e7 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -54,4 +55,12 @@ JS::NonnullGCPtr 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 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 3dbe155259e..7033e759b91 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 type; }; +WebIDL::ExceptionOr byte_sequence_as_body(JS::Realm&, ReadonlyBytes); + }