mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
The end goal here is for LibHTTP to be the home of our RFC 9111 (HTTP caching) implementation. We currently have one implementation in LibWeb for our in-memory cache and another in RequestServer for our disk cache. The implementations both largely revolve around interacting with HTTP headers. But in LibWeb, we are using Fetch's header infra, and in RS we are using are home-grown header infra from LibHTTP. So to give these a common denominator, this patch replaces the LibHTTP implementation with Fetch's infra. Our existing LibHTTP implementation was not particularly compliant with any spec, so this at least gives us a standards-based common implementation. This migration also required moving a handful of other Fetch AOs over to LibHTTP. (It turns out these AOs were all from the Fetch/Infra/HTTP folder, so perhaps it makes sense for LibHTTP to be the implementation of that entire set of facilities.)
74 lines
2.9 KiB
C++
74 lines
2.9 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/HashMap.h>
|
|
#include <LibHTTP/HeaderList.h>
|
|
#include <LibIPC/ConnectionToServer.h>
|
|
#include <LibRequests/CacheSizes.h>
|
|
#include <LibRequests/RequestTimingInfo.h>
|
|
#include <LibRequests/WebSocket.h>
|
|
#include <LibWebSocket/WebSocket.h>
|
|
#include <RequestServer/RequestClientEndpoint.h>
|
|
#include <RequestServer/RequestServerEndpoint.h>
|
|
|
|
namespace Requests {
|
|
|
|
class Request;
|
|
|
|
class RequestClient final
|
|
: public IPC::ConnectionToServer<RequestClientEndpoint, RequestServerEndpoint>
|
|
, public RequestClientEndpoint {
|
|
C_OBJECT_ABSTRACT(RequestClient)
|
|
|
|
public:
|
|
using InitTransport = Messages::RequestServer::InitTransport;
|
|
|
|
explicit RequestClient(NonnullOwnPtr<IPC::Transport>);
|
|
virtual ~RequestClient() override;
|
|
|
|
RefPtr<Request> start_request(ByteString const& method, URL::URL const&, Optional<HTTP::HeaderList const&> request_headers = {}, ReadonlyBytes request_body = {}, Core::ProxyData const& = {});
|
|
|
|
RefPtr<WebSocket> websocket_connect(URL::URL const&, ByteString const& origin, Vector<ByteString> const& protocols, Vector<ByteString> const& extensions, HTTP::HeaderList const& request_headers);
|
|
|
|
void ensure_connection(URL::URL const&, ::RequestServer::CacheLevel);
|
|
|
|
bool stop_request(Badge<Request>, Request&);
|
|
bool set_certificate(Badge<Request>, Request&, ByteString, ByteString);
|
|
|
|
NonnullRefPtr<Core::Promise<CacheSizes>> estimate_cache_size_accessed_since(UnixDateTime since);
|
|
|
|
Function<void()> on_request_server_died;
|
|
|
|
private:
|
|
virtual void die() override;
|
|
|
|
virtual void request_started(i32, IPC::File) override;
|
|
virtual void request_finished(i32, u64, RequestTimingInfo, Optional<NetworkError>) override;
|
|
virtual void certificate_requested(i32) override;
|
|
virtual void headers_became_available(i32, Vector<HTTP::Header>, Optional<u32>, Optional<String>) override;
|
|
|
|
virtual void websocket_connected(i64 websocket_id) override;
|
|
virtual void websocket_received(i64 websocket_id, bool, ByteBuffer) override;
|
|
virtual void websocket_errored(i64 websocket_id, i32) override;
|
|
virtual void websocket_closed(i64 websocket_id, u16, ByteString, bool) override;
|
|
virtual void websocket_ready_state_changed(i64 websocket_id, u32 ready_state) override;
|
|
virtual void websocket_subprotocol(i64 websocket_id, ByteString subprotocol) override;
|
|
virtual void websocket_certificate_requested(i64 websocket_id) override;
|
|
|
|
virtual void estimated_cache_size(u64 cache_size_estimation_id, CacheSizes sizes) override;
|
|
|
|
HashMap<i32, RefPtr<Request>> m_requests;
|
|
|
|
HashMap<i64, NonnullRefPtr<WebSocket>> m_websockets;
|
|
i64 m_next_websocket_id { 0 };
|
|
|
|
HashMap<u64, NonnullRefPtr<Core::Promise<CacheSizes>>> m_pending_cache_size_estimations;
|
|
u64 m_next_cache_size_estimation_id { 0 };
|
|
};
|
|
|
|
}
|