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
|
|
|
|
|
|
2025-10-23 21:44:55 -03:00
|
|
|
#include <AK/Badge.h>
|
2021-04-23 17:45:52 -03:00
|
|
|
#include <AK/HashMap.h>
|
2026-04-26 01:56:19 -03:00
|
|
|
#include <AK/Optional.h>
|
|
|
|
|
#include <AK/Time.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-02-05 14:25:14 -03:00
|
|
|
#include <LibHTTP/Cache/DiskCacheSettings.h>
|
2026-05-03 14:12:09 -03:00
|
|
|
#include <LibHTTP/Cache/Utilities.h>
|
2026-02-15 11:23:55 -03:00
|
|
|
#include <LibHTTP/Forward.h>
|
2022-02-25 07:18:30 -03:00
|
|
|
#include <LibIPC/ConnectionFromClient.h>
|
2026-04-17 08:31:36 -03:00
|
|
|
#include <LibRequests/WebSocket.h>
|
2024-03-05 21:50:52 -03:00
|
|
|
#include <LibWebSocket/WebSocket.h>
|
2025-10-22 20:26:17 -03:00
|
|
|
#include <RequestServer/Forward.h>
|
2021-04-23 17:45:52 -03:00
|
|
|
#include <RequestServer/RequestClientEndpoint.h>
|
|
|
|
|
#include <RequestServer/RequestServerEndpoint.h>
|
|
|
|
|
|
|
|
|
|
namespace RequestServer {
|
|
|
|
|
|
2022-02-25 07:18:30 -03:00
|
|
|
class ConnectionFromClient final
|
|
|
|
|
: public IPC::ConnectionFromClient<RequestClientEndpoint, RequestServerEndpoint> {
|
|
|
|
|
C_OBJECT(ConnectionFromClient);
|
2021-04-23 17:45:52 -03:00
|
|
|
|
|
|
|
|
public:
|
2026-02-15 11:23:55 -03:00
|
|
|
enum class IsPrimaryConnection {
|
|
|
|
|
No,
|
|
|
|
|
Yes,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using ConnectionMap = HashMap<int, NonnullRefPtr<ConnectionFromClient>>;
|
|
|
|
|
|
2024-07-27 19:22:58 -03:00
|
|
|
~ConnectionFromClient() override;
|
2021-04-23 17:45:52 -03:00
|
|
|
|
|
|
|
|
virtual void die() override;
|
|
|
|
|
|
2026-02-07 16:06:22 -03:00
|
|
|
static Optional<ConnectionFromClient&> primary_connection();
|
|
|
|
|
|
|
|
|
|
void start_revalidation_request(Badge<Request>, ByteString method, URL::URL, NonnullRefPtr<HTTP::HeaderList> request_headers, ByteBuffer request_body, HTTP::Cookie::IncludeCredentials, Core::ProxyData proxy_data);
|
2025-12-12 10:33:17 -03:00
|
|
|
void request_complete(Badge<Request>, Request const&);
|
2025-10-23 21:44:55 -03:00
|
|
|
|
2024-07-22 17:52:21 -03:00
|
|
|
private:
|
2026-02-15 11:23:55 -03:00
|
|
|
ConnectionFromClient(NonnullOwnPtr<IPC::Transport>, IsPrimaryConnection, ConnectionMap&, Optional<HTTP::DiskCache&>);
|
2024-07-22 17:52:21 -03:00
|
|
|
|
2025-01-03 13:19:46 -03:00
|
|
|
virtual Messages::RequestServer::InitTransportResponse init_transport(int peer_pid) override;
|
2024-07-22 17:52:21 -03:00
|
|
|
virtual Messages::RequestServer::ConnectNewClientResponse connect_new_client() override;
|
2025-08-09 14:04:48 -03:00
|
|
|
virtual Messages::RequestServer::ConnectNewClientsResponse connect_new_clients(size_t count) override;
|
|
|
|
|
|
2026-02-05 14:25:14 -03:00
|
|
|
virtual void set_disk_cache_settings(HTTP::DiskCacheSettings) override;
|
|
|
|
|
|
2025-03-08 14:22:39 -03:00
|
|
|
virtual Messages::RequestServer::IsSupportedProtocolResponse is_supported_protocol(ByteString) override;
|
2025-05-13 07:34:55 -03:00
|
|
|
virtual void set_dns_server(ByteString host_or_address, u16 port, bool use_tls, bool validate_dnssec_locally) override;
|
2025-04-07 22:56:35 -03:00
|
|
|
virtual void set_use_system_dns() override;
|
2026-02-07 16:06:22 -03:00
|
|
|
virtual void start_request(u64 request_id, ByteString, URL::URL, Vector<HTTP::Header>, ByteBuffer, HTTP::CacheMode, HTTP::Cookie::IncludeCredentials, Core::ProxyData) override;
|
2025-12-12 11:56:53 -03:00
|
|
|
virtual Messages::RequestServer::StopRequestResponse stop_request(u64 request_id) override;
|
|
|
|
|
virtual Messages::RequestServer::SetCertificateResponse set_certificate(u64 request_id, ByteString, ByteString) override;
|
2025-12-11 16:31:12 -03:00
|
|
|
virtual void ensure_connection(u64 request_id, URL::URL url, ::RequestServer::CacheLevel cache_level) override;
|
2024-07-22 17:52:21 -03:00
|
|
|
|
2026-04-13 17:53:29 -03:00
|
|
|
virtual void retrieved_http_cookie(int client_id, u64 request_id, RequestServer::RequestType request_type, String cookie) override;
|
2026-02-07 16:06:22 -03:00
|
|
|
|
2025-11-02 15:10:27 -03:00
|
|
|
virtual void estimate_cache_size_accessed_since(u64 cache_size_estimation_id, UnixDateTime since) override;
|
2025-11-02 18:44:30 -03:00
|
|
|
virtual void remove_cache_entries_accessed_since(UnixDateTime since) override;
|
2026-05-03 15:04:35 -03:00
|
|
|
virtual Messages::RequestServer::StoreCacheAssociatedDataResponse store_cache_associated_data(URL::URL, ByteString method, Vector<HTTP::Header> request_headers, Optional<u64> vary_key, HTTP::CacheEntryAssociatedData, Core::AnonymousBuffer) override;
|
|
|
|
|
virtual Messages::RequestServer::RetrieveCacheAssociatedDataResponse retrieve_cache_associated_data(URL::URL, ByteString method, Vector<HTTP::Header> request_headers, Optional<u64> vary_key, HTTP::CacheEntryAssociatedData) override;
|
2026-05-11 10:57:16 -03:00
|
|
|
virtual Messages::RequestServer::CreateSyntheticCacheEntryResponse create_synthetic_cache_entry(URL::URL, ByteString method) override;
|
2025-10-09 15:24:47 -03:00
|
|
|
|
2025-12-11 13:58:50 -03:00
|
|
|
virtual void websocket_connect(u64 websocket_id, URL::URL, ByteString, Vector<ByteString>, Vector<ByteString>, Vector<HTTP::Header>) override;
|
|
|
|
|
virtual void websocket_send(u64 websocket_id, bool, ByteBuffer) override;
|
2026-05-14 09:39:07 -03:00
|
|
|
virtual void websocket_send_shared(u64 websocket_id, bool, Core::AnonymousBuffer) override;
|
2025-12-11 13:58:50 -03:00
|
|
|
virtual void websocket_close(u64 websocket_id, u16, ByteString) override;
|
|
|
|
|
virtual Messages::RequestServer::WebsocketSetCertificateResponse websocket_set_certificate(u64, ByteString, ByteString) override;
|
2024-07-22 17:52:21 -03:00
|
|
|
|
2024-09-05 08:20:09 -03:00
|
|
|
static int on_socket_callback(void*, int sockfd, int what, void* user_data, void*);
|
|
|
|
|
static int on_timeout_callback(void*, long timeout_ms, void* user_data);
|
2025-10-23 21:44:55 -03:00
|
|
|
void check_active_requests();
|
2026-04-17 08:31:36 -03:00
|
|
|
void fail_websocket(u64 websocket_id, Requests::WebSocket::Error);
|
2024-09-05 08:20:09 -03:00
|
|
|
|
2026-03-11 16:10:08 -03:00
|
|
|
ErrorOr<IPC::TransportHandle> create_client_socket();
|
2026-02-15 11:23:55 -03:00
|
|
|
|
|
|
|
|
ConnectionMap& m_connections;
|
|
|
|
|
Optional<HTTP::DiskCache&> m_disk_cache;
|
2024-05-08 15:15:05 -03:00
|
|
|
|
2024-09-05 08:20:09 -03:00
|
|
|
void* m_curl_multi { nullptr };
|
2025-10-23 21:44:55 -03:00
|
|
|
|
2025-12-12 11:56:53 -03:00
|
|
|
HashMap<u64, NonnullOwnPtr<Request>> m_active_requests;
|
2025-12-12 10:33:17 -03:00
|
|
|
HashMap<u64, NonnullOwnPtr<Request>> m_active_revalidation_requests;
|
2026-03-31 07:39:59 -03:00
|
|
|
HashTable<u64> m_pending_websockets;
|
2025-12-11 13:58:50 -03:00
|
|
|
HashMap<u64, RefPtr<WebSocket::WebSocket>> m_websockets;
|
2025-10-23 21:44:55 -03:00
|
|
|
|
2024-09-05 08:20:09 -03:00
|
|
|
RefPtr<Core::Timer> m_timer;
|
|
|
|
|
HashMap<int, NonnullRefPtr<Core::Notifier>> m_read_notifiers;
|
|
|
|
|
HashMap<int, NonnullRefPtr<Core::Notifier>> m_write_notifiers;
|
2025-10-23 21:44:55 -03:00
|
|
|
|
2024-11-01 19:53:43 -03:00
|
|
|
NonnullRefPtr<Resolver> m_resolver;
|
2025-07-07 12:03:37 -03:00
|
|
|
ByteString m_alt_svc_cache_path;
|
2025-12-12 10:33:17 -03:00
|
|
|
|
|
|
|
|
u64 m_next_revalidation_request_id { 0 };
|
2026-04-26 01:56:19 -03:00
|
|
|
|
|
|
|
|
Optional<MonotonicTime> m_burst_window_started_at;
|
|
|
|
|
u64 m_requests_in_burst_window { 0 };
|
2021-04-23 17:45:52 -03:00
|
|
|
};
|
|
|
|
|
|
2025-02-20 08:18:37 -03:00
|
|
|
constexpr inline uintptr_t websocket_private_tag = 0x1;
|
|
|
|
|
|
2021-04-23 17:45:52 -03:00
|
|
|
}
|