2021-04-23 22:45:52 +02:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2021-04-23 22:45:52 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/HashMap.h>
|
2024-06-09 11:28:37 +02:00
|
|
|
#include <LibHTTP/HeaderMap.h>
|
2022-02-25 12:27:37 +02:00
|
|
|
#include <LibIPC/ConnectionToServer.h>
|
2025-02-26 13:28:21 +00:00
|
|
|
#include <LibRequests/RequestTimingInfo.h>
|
2024-08-06 21:51:20 -06:00
|
|
|
#include <LibRequests/WebSocket.h>
|
2024-03-06 01:50:52 +01:00
|
|
|
#include <LibWebSocket/WebSocket.h>
|
2021-04-23 22:45:52 +02:00
|
|
|
#include <RequestServer/RequestClientEndpoint.h>
|
|
|
|
#include <RequestServer/RequestServerEndpoint.h>
|
|
|
|
|
2024-08-06 21:51:20 -06:00
|
|
|
namespace Requests {
|
2021-04-23 22:45:52 +02:00
|
|
|
|
|
|
|
class Request;
|
|
|
|
|
2021-05-23 09:52:41 +02:00
|
|
|
class RequestClient final
|
2022-02-25 12:27:37 +02:00
|
|
|
: public IPC::ConnectionToServer<RequestClientEndpoint, RequestServerEndpoint>
|
2021-04-23 22:45:52 +02:00
|
|
|
, public RequestClientEndpoint {
|
2024-11-21 12:46:45 -07:00
|
|
|
C_OBJECT_ABSTRACT(RequestClient)
|
2021-04-23 22:45:52 +02:00
|
|
|
|
|
|
|
public:
|
2025-01-03 21:19:46 +05:00
|
|
|
using InitTransport = Messages::RequestServer::InitTransport;
|
|
|
|
|
2024-10-22 15:47:33 -06:00
|
|
|
explicit RequestClient(IPC::Transport);
|
2024-06-16 10:38:35 +02:00
|
|
|
virtual ~RequestClient() override;
|
2023-08-01 14:41:13 -06:00
|
|
|
|
2024-06-09 13:46:04 +02:00
|
|
|
RefPtr<Request> start_request(ByteString const& method, URL::URL const&, HTTP::HeaderMap const& request_headers = {}, ReadonlyBytes request_body = {}, Core::ProxyData const& = {});
|
2021-04-23 22:45:52 +02:00
|
|
|
|
2024-06-22 10:28:14 +02:00
|
|
|
RefPtr<WebSocket> websocket_connect(const URL::URL&, ByteString const& origin = {}, Vector<ByteString> const& protocols = {}, Vector<ByteString> const& extensions = {}, HTTP::HeaderMap const& request_headers = {});
|
2024-03-06 01:50:52 +01:00
|
|
|
|
2024-03-18 16:22:27 +13:00
|
|
|
void ensure_connection(URL::URL const&, ::RequestServer::CacheLevel);
|
2021-09-28 00:06:52 +03:30
|
|
|
|
2021-04-23 22:45:52 +02:00
|
|
|
bool stop_request(Badge<Request>, Request&);
|
2023-12-16 17:49:34 +03:30
|
|
|
bool set_certificate(Badge<Request>, Request&, ByteString, ByteString);
|
2021-04-23 22:45:52 +02:00
|
|
|
|
|
|
|
private:
|
2024-06-06 07:16:14 -04:00
|
|
|
virtual void die() override;
|
|
|
|
|
2025-03-08 12:22:39 -05:00
|
|
|
virtual void request_started(i32, IPC::File) override;
|
|
|
|
virtual void request_finished(i32, u64, RequestTimingInfo, Optional<NetworkError>) override;
|
2021-05-02 19:54:34 +02:00
|
|
|
virtual void certificate_requested(i32) override;
|
2025-03-08 12:22:39 -05:00
|
|
|
virtual void headers_became_available(i32, HTTP::HeaderMap, Optional<u32>, Optional<String>) override;
|
2021-04-23 22:45:52 +02:00
|
|
|
|
2024-09-18 10:28:55 +02:00
|
|
|
virtual void websocket_connected(i64 websocket_id) override;
|
2025-03-08 12:22:39 -05:00
|
|
|
virtual void websocket_received(i64 websocket_id, bool, ByteBuffer) override;
|
2024-09-18 10:28:55 +02:00
|
|
|
virtual void websocket_errored(i64 websocket_id, i32) override;
|
2025-03-08 12:22:39 -05:00
|
|
|
virtual void websocket_closed(i64 websocket_id, u16, ByteString, bool) override;
|
2024-09-18 10:28:55 +02:00
|
|
|
virtual void websocket_ready_state_changed(i64 websocket_id, u32 ready_state) override;
|
2025-03-08 12:22:39 -05:00
|
|
|
virtual void websocket_subprotocol(i64 websocket_id, ByteString subprotocol) override;
|
2024-09-18 10:28:55 +02:00
|
|
|
virtual void websocket_certificate_requested(i64 websocket_id) override;
|
2024-03-06 01:50:52 +01:00
|
|
|
|
2021-04-23 22:45:52 +02:00
|
|
|
HashMap<i32, RefPtr<Request>> m_requests;
|
2024-09-18 10:28:55 +02:00
|
|
|
HashMap<i64, NonnullRefPtr<WebSocket>> m_websockets;
|
|
|
|
|
|
|
|
i64 m_next_websocket_id { 0 };
|
2021-04-23 22:45:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|