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 #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 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 type; }; +WebIDL::ExceptionOr byte_sequence_as_body(JS::Realm&, ReadonlyBytes); + }