diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 70981a0111..ba70de299e 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -119,6 +119,7 @@ set(SOURCES Encoding/TextEncoder.cpp Fetch/Infrastructure/HTTP.cpp Fetch/Infrastructure/URL.cpp + Fetch/Infrastructure/HTTP/Bodies.cpp Fetch/Infrastructure/HTTP/Headers.cpp Fetch/Infrastructure/HTTP/Methods.cpp Fetch/Infrastructure/HTTP/Statuses.cpp diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp new file mode 100644 index 0000000000..2c9932ab7f --- /dev/null +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +namespace Web::Fetch { + +Body::Body(ReadableStreamDummy stream) + : m_stream(stream) +{ +} + +Body::Body(ReadableStreamDummy stream, SourceType source, Optional length) + : m_stream(stream) + , m_source(move(source)) + , m_length(move(length)) +{ +} + +} diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h new file mode 100644 index 0000000000..9759daf49f --- /dev/null +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include + +namespace Web::Fetch { + +// https://fetch.spec.whatwg.org/#concept-body +class Body final { +public: + using SourceType = Variant; + + struct ReadableStreamDummy { }; + + explicit Body(ReadableStreamDummy); + Body(ReadableStreamDummy, SourceType, Optional); + + [[nodiscard]] ReadableStreamDummy const& stream() { return m_stream; } + [[nodiscard]] SourceType const& source() const { return m_source; } + [[nodiscard]] Optional const& length() const { return m_length; } + +private: + // https://fetch.spec.whatwg.org/#concept-body-stream + // A stream (a ReadableStream object). + // FIXME: Just a placeholder for now. + ReadableStreamDummy m_stream; + + // https://fetch.spec.whatwg.org/#concept-body-source + // A source (null, a byte sequence, a Blob object, or a FormData object), initially null. + SourceType m_source; + + // https://fetch.spec.whatwg.org/#concept-body-total-bytes + // A length (null or an integer), initially null. + Optional m_length; +}; + +// https://fetch.spec.whatwg.org/#body-with-type +// A body with type is a tuple that consists of a body (a body) and a type (a header value or null). +struct BodyWithType { + Body body; + Optional type; +}; + +} diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 9a0f18a4c6..3fdd3f4d73 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -170,6 +170,7 @@ class TextEncoder; } namespace Web::Fetch { +class Body; struct Header; class HeaderList; }