2021-04-23 17:45:52 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2021-04-23 17:45:52 -03:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/HashMap.h>
|
2026-05-03 14:12:09 -03:00
|
|
|
#include <LibCore/AnonymousBuffer.h>
|
2026-01-20 19:12:36 -03:00
|
|
|
#include <LibHTTP/Cache/CacheMode.h>
|
2026-05-03 14:12:09 -03:00
|
|
|
#include <LibHTTP/Cache/Utilities.h>
|
2026-02-07 16:06:22 -03:00
|
|
|
#include <LibHTTP/Cookie/IncludeCredentials.h>
|
2025-11-26 16:13:23 -03:00
|
|
|
#include <LibHTTP/HeaderList.h>
|
2022-02-25 07:27:37 -03:00
|
|
|
#include <LibIPC/ConnectionToServer.h>
|
2025-11-02 15:10:27 -03:00
|
|
|
#include <LibRequests/CacheSizes.h>
|
2025-02-26 10:28:21 -03:00
|
|
|
#include <LibRequests/RequestTimingInfo.h>
|
2024-08-07 00:51:20 -03:00
|
|
|
#include <LibRequests/WebSocket.h>
|
2024-03-05 21:50:52 -03:00
|
|
|
#include <LibWebSocket/WebSocket.h>
|
2021-04-23 17:45:52 -03:00
|
|
|
#include <RequestServer/RequestClientEndpoint.h>
|
|
|
|
|
#include <RequestServer/RequestServerEndpoint.h>
|
|
|
|
|
|
2024-08-07 00:51:20 -03:00
|
|
|
namespace Requests {
|
2021-04-23 17:45:52 -03:00
|
|
|
|
|
|
|
|
class Request;
|
|
|
|
|
|
2021-05-23 04:52:41 -03:00
|
|
|
class RequestClient final
|
2022-02-25 07:27:37 -03:00
|
|
|
: public IPC::ConnectionToServer<RequestClientEndpoint, RequestServerEndpoint>
|
2021-04-23 17:45:52 -03:00
|
|
|
, public RequestClientEndpoint {
|
2024-11-21 16:46:45 -03:00
|
|
|
C_OBJECT_ABSTRACT(RequestClient)
|
2021-04-23 17:45:52 -03:00
|
|
|
|
|
|
|
|
public:
|
2025-01-03 13:19:46 -03:00
|
|
|
using InitTransport = Messages::RequestServer::InitTransport;
|
|
|
|
|
|
2025-04-08 17:01:46 -03:00
|
|
|
explicit RequestClient(NonnullOwnPtr<IPC::Transport>);
|
2024-06-16 05:38:35 -03:00
|
|
|
virtual ~RequestClient() override;
|
2023-08-01 17:41:13 -03:00
|
|
|
|
2026-02-07 16:06:22 -03:00
|
|
|
RefPtr<Request> start_request(ByteString const& method, URL::URL const&, Optional<HTTP::HeaderList const&> request_headers = {}, ReadonlyBytes request_body = {}, HTTP::CacheMode = HTTP::CacheMode::Default, HTTP::Cookie::IncludeCredentials = HTTP::Cookie::IncludeCredentials::Yes, Core::ProxyData const& = {});
|
2021-04-23 17:45:52 -03:00
|
|
|
bool stop_request(Badge<Request>, Request&);
|
2026-02-07 09:50:20 -03:00
|
|
|
void ensure_connection(URL::URL const&, RequestServer::CacheLevel);
|
|
|
|
|
|
2023-12-16 11:19:34 -03:00
|
|
|
bool set_certificate(Badge<Request>, Request&, ByteString, ByteString);
|
2021-04-23 17:45:52 -03:00
|
|
|
|
2026-02-07 09:50:20 -03:00
|
|
|
RefPtr<WebSocket> websocket_connect(URL::URL const&, ByteString const& origin, Vector<ByteString> const& protocols, Vector<ByteString> const& extensions, HTTP::HeaderList const& request_headers);
|
|
|
|
|
|
2025-11-02 15:10:27 -03:00
|
|
|
NonnullRefPtr<Core::Promise<CacheSizes>> estimate_cache_size_accessed_since(UnixDateTime since);
|
2026-05-03 15:04:35 -03:00
|
|
|
ErrorOr<bool> store_cache_associated_data(URL::URL const&, ByteString const& method, Optional<HTTP::HeaderList const&> request_headers, Optional<u64> vary_key, HTTP::CacheEntryAssociatedData, ReadonlyBytes);
|
|
|
|
|
ErrorOr<Optional<Core::AnonymousBuffer>> retrieve_cache_associated_data(URL::URL const&, ByteString const& method, Optional<HTTP::HeaderList const&> request_headers, Optional<u64> vary_key, HTTP::CacheEntryAssociatedData);
|
2026-05-11 10:57:16 -03:00
|
|
|
ErrorOr<bool> create_synthetic_cache_entry(URL::URL const&, ByteString const& method);
|
2025-11-02 15:10:27 -03:00
|
|
|
|
2026-02-07 16:06:22 -03:00
|
|
|
Function<String(URL::URL const&)> on_retrieve_http_cookie;
|
2025-08-09 14:07:09 -03:00
|
|
|
Function<void()> on_request_server_died;
|
|
|
|
|
|
2021-04-23 17:45:52 -03:00
|
|
|
private:
|
2024-06-06 08:16:14 -03:00
|
|
|
virtual void die() override;
|
|
|
|
|
|
2025-12-12 11:56:53 -03:00
|
|
|
virtual void request_started(u64 request_id, IPC::File) override;
|
2026-05-15 09:37:07 -03:00
|
|
|
virtual void request_body_file_available(u64 request_id, IPC::File, u64 offset, u64 size) override;
|
2026-05-15 09:58:56 -03:00
|
|
|
virtual void request_cached_body_file_available(u64 request_id, IPC::File, u64 offset, u64 size) override;
|
2025-12-12 11:56:53 -03:00
|
|
|
virtual void request_finished(u64 request_id, u64, RequestTimingInfo, Optional<NetworkError>) override;
|
2026-05-15 11:34:54 -03:00
|
|
|
virtual void headers_became_available(u64 request_id, Vector<HTTP::Header>, Optional<u32>, Optional<String>, Optional<IPC::File>, u64 javascript_bytecode_size, Optional<u64>) override;
|
2021-04-23 17:45:52 -03:00
|
|
|
|
2026-04-13 17:53:29 -03:00
|
|
|
virtual void retrieve_http_cookie(int client_id, u64 request_id, RequestServer::RequestType request_type, URL::URL url) override;
|
2026-02-07 16:06:22 -03:00
|
|
|
|
2026-02-07 09:50:20 -03:00
|
|
|
virtual void certificate_requested(u64 request_id) override;
|
|
|
|
|
|
2025-12-11 13:58:50 -03:00
|
|
|
virtual void websocket_connected(u64 websocket_id) override;
|
|
|
|
|
virtual void websocket_received(u64 websocket_id, bool, ByteBuffer) override;
|
|
|
|
|
virtual void websocket_errored(u64 websocket_id, i32) override;
|
|
|
|
|
virtual void websocket_closed(u64 websocket_id, u16, ByteString, bool) override;
|
|
|
|
|
virtual void websocket_ready_state_changed(u64 websocket_id, u32 ready_state) override;
|
|
|
|
|
virtual void websocket_subprotocol(u64 websocket_id, ByteString subprotocol) override;
|
|
|
|
|
virtual void websocket_certificate_requested(u64 websocket_id) override;
|
2024-03-05 21:50:52 -03:00
|
|
|
|
2025-11-02 15:10:27 -03:00
|
|
|
virtual void estimated_cache_size(u64 cache_size_estimation_id, CacheSizes sizes) override;
|
|
|
|
|
|
2025-12-12 11:56:53 -03:00
|
|
|
HashMap<u64, RefPtr<Request>> m_requests;
|
2025-12-11 16:31:12 -03:00
|
|
|
u64 m_next_request_id { 0 };
|
2024-09-18 05:28:55 -03:00
|
|
|
|
2025-12-11 13:58:50 -03:00
|
|
|
HashMap<u64, NonnullRefPtr<WebSocket>> m_websockets;
|
|
|
|
|
u64 m_next_websocket_id { 0 };
|
2025-11-02 15:10:27 -03:00
|
|
|
|
|
|
|
|
HashMap<u64, NonnullRefPtr<Core::Promise<CacheSizes>>> m_pending_cache_size_estimations;
|
|
|
|
|
u64 m_next_cache_size_estimation_id { 0 };
|
2021-04-23 17:45:52 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|