Bodies.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/ByteBuffer.h>
  8. #include <AK/Forward.h>
  9. #include <AK/Optional.h>
  10. #include <AK/Variant.h>
  11. namespace Web::Fetch {
  12. // https://fetch.spec.whatwg.org/#concept-body
  13. class Body final {
  14. public:
  15. using SourceType = Variant<Empty, ByteBuffer>;
  16. struct ReadableStreamDummy { };
  17. explicit Body(ReadableStreamDummy);
  18. Body(ReadableStreamDummy, SourceType, Optional<u64>);
  19. [[nodiscard]] ReadableStreamDummy const& stream() { return m_stream; }
  20. [[nodiscard]] SourceType const& source() const { return m_source; }
  21. [[nodiscard]] Optional<u64> const& length() const { return m_length; }
  22. private:
  23. // https://fetch.spec.whatwg.org/#concept-body-stream
  24. // A stream (a ReadableStream object).
  25. // FIXME: Just a placeholder for now.
  26. ReadableStreamDummy m_stream;
  27. // https://fetch.spec.whatwg.org/#concept-body-source
  28. // A source (null, a byte sequence, a Blob object, or a FormData object), initially null.
  29. SourceType m_source;
  30. // https://fetch.spec.whatwg.org/#concept-body-total-bytes
  31. // A length (null or an integer), initially null.
  32. Optional<u64> m_length;
  33. };
  34. // https://fetch.spec.whatwg.org/#body-with-type
  35. // A body with type is a tuple that consists of a body (a body) and a type (a header value or null).
  36. struct BodyWithType {
  37. Body body;
  38. Optional<ByteBuffer> type;
  39. };
  40. }