1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:48:12 +00:00

LibWeb: Implement container class for fetch algorithms

This commit is contained in:
Linus Groh 2022-10-13 19:23:43 +02:00
parent dd5d3e2f4f
commit ba31547fa0
4 changed files with 88 additions and 0 deletions

View file

@ -125,6 +125,7 @@ set(SOURCES
Fetch/Headers.cpp
Fetch/HeadersIterator.cpp
Fetch/Infrastructure/ConnectionTimingInfo.cpp
Fetch/Infrastructure/FetchAlgorithms.cpp
Fetch/Infrastructure/FetchController.cpp
Fetch/Infrastructure/FetchTimingInfo.cpp
Fetch/Infrastructure/HTTP.cpp

View file

@ -0,0 +1,28 @@
/*
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Heap/Heap.h>
#include <LibJS/Runtime/VM.h>
#include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>
namespace Web::Fetch::Infrastructure {
JS::NonnullGCPtr<FetchAlgorithms> FetchAlgorithms::create(JS::VM& vm, Input input)
{
return { *vm.heap().allocate_without_realm<FetchAlgorithms>(move(input)) };
}
FetchAlgorithms::FetchAlgorithms(Input input)
: m_process_request_body_chunk_length(move(input.process_request_body_chunk_length))
, m_process_request_end_of_body(move(input.process_request_end_of_body))
, m_process_early_hints_response(move(input.process_early_hints_response))
, m_process_response(move(input.process_response))
, m_process_response_end_of_body(move(input.process_response_end_of_body))
, m_process_response_consume_body(move(input.process_response_consume_body))
{
}
}

View file

@ -0,0 +1,58 @@
/*
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Optional.h>
#include <LibJS/Heap/Cell.h>
#include <LibJS/SafeFunction.h>
#include <LibWeb/Forward.h>
namespace Web::Fetch::Infrastructure {
// https://fetch.spec.whatwg.org/#fetch-elsewhere-fetch
class FetchAlgorithms : public JS::Cell {
JS_CELL(FetchAlgorithms, JS::Cell);
public:
struct ConsumeBodyFailureTag { };
using ProcessRequestBodyChunkLengthFunction = JS::SafeFunction<void(u64)>;
using ProcessRequestEndOfBodyFunction = JS::SafeFunction<void()>;
using ProcessEarlyHintsResponseFunction = JS::SafeFunction<void(JS::NonnullGCPtr<Infrastructure::Response>)>;
using ProcessResponseFunction = JS::SafeFunction<void(JS::NonnullGCPtr<Infrastructure::Response>)>;
using ProcessResponseEndOfBodyFunction = JS::SafeFunction<void(JS::NonnullGCPtr<Infrastructure::Response>)>;
using ProcessResponseConsumeBodyFunction = JS::SafeFunction<void(JS::NonnullGCPtr<Infrastructure::Response>, Variant<Empty, ConsumeBodyFailureTag, ByteBuffer>)>;
struct Input {
Optional<ProcessRequestBodyChunkLengthFunction> process_request_body_chunk_length;
Optional<ProcessRequestEndOfBodyFunction> process_request_end_of_body;
Optional<ProcessEarlyHintsResponseFunction> process_early_hints_response;
Optional<ProcessResponseFunction> process_response;
Optional<ProcessResponseEndOfBodyFunction> process_response_end_of_body;
Optional<ProcessResponseConsumeBodyFunction> process_response_consume_body;
};
[[nodiscard]] static JS::NonnullGCPtr<FetchAlgorithms> create(JS::VM&, Input);
Optional<ProcessRequestBodyChunkLengthFunction> const& process_request_body_chunk_length() const { return m_process_request_body_chunk_length; }
Optional<ProcessRequestEndOfBodyFunction> const& process_request_end_of_body() const { return m_process_request_end_of_body; }
Optional<ProcessEarlyHintsResponseFunction> const& process_early_hints_response() const { return m_process_early_hints_response; }
Optional<ProcessResponseFunction> const& process_response() const { return m_process_response; }
Optional<ProcessResponseEndOfBodyFunction> const& process_response_end_of_body() const { return m_process_response_end_of_body; }
Optional<ProcessResponseConsumeBodyFunction> const& process_response_consume_body() const { return m_process_response_consume_body; }
private:
explicit FetchAlgorithms(Input);
Optional<ProcessRequestBodyChunkLengthFunction> m_process_request_body_chunk_length;
Optional<ProcessRequestEndOfBodyFunction> m_process_request_end_of_body;
Optional<ProcessEarlyHintsResponseFunction> m_process_early_hints_response;
Optional<ProcessResponseFunction> m_process_response;
Optional<ProcessResponseEndOfBodyFunction> m_process_response_end_of_body;
Optional<ProcessResponseConsumeBodyFunction> m_process_response_consume_body;
};
}

View file

@ -193,6 +193,7 @@ namespace Web::Fetch::Infrastructure {
class Body;
struct BodyWithType;
class ConnectionTimingInfo;
class FetchAlgorithms;
class FetchController;
class FetchTimingInfo;
struct Header;