mirror of
https://github.com/SerenityOS/serenity.git
synced 2026-11-07 04:29:30 -10:00
This was available on Serenity by sending SIGINFO to RequestServer. Add an IPC so we may see this info while running the browser. (cherry picked from commit e75ba44f377b9ba15186a0af89a6c52777038527)
94 lines
3.5 KiB
C++
94 lines
3.5 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <[email protected]>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/HashMap.h>
|
|
#include <LibCore/SharedCircularQueue.h>
|
|
#include <LibIPC/ConnectionFromClient.h>
|
|
#include <LibThreading/MutexProtected.h>
|
|
#include <LibThreading/ThreadPool.h>
|
|
#include <LibWebSocket/WebSocket.h>
|
|
#include <RequestServer/Forward.h>
|
|
#include <RequestServer/RequestClientEndpoint.h>
|
|
#include <RequestServer/RequestServerEndpoint.h>
|
|
|
|
namespace RequestServer {
|
|
|
|
class ConnectionFromClient final
|
|
: public IPC::ConnectionFromClient<RequestClientEndpoint, RequestServerEndpoint> {
|
|
C_OBJECT(ConnectionFromClient);
|
|
|
|
public:
|
|
~ConnectionFromClient() override;
|
|
|
|
virtual void die() override;
|
|
|
|
void did_receive_headers(Badge<Request>, Request&);
|
|
void did_finish_request(Badge<Request>, Request&, bool success);
|
|
void did_progress_request(Badge<Request>, Request&);
|
|
void did_request_certificates(Badge<Request>, Request&);
|
|
|
|
template<typename Pool>
|
|
struct Looper : public Threading::ThreadPoolLooper<Pool> {
|
|
Looper(int pipe_fd)
|
|
: notifier(Core::Notifier::construct(pipe_fd, Core::NotificationType::Read))
|
|
{
|
|
}
|
|
|
|
IterationDecision next(Pool& pool, bool wait);
|
|
Core::EventLoop event_loop;
|
|
NonnullRefPtr<Core::Notifier> notifier;
|
|
bool done { false };
|
|
};
|
|
|
|
struct StartRequest {
|
|
i32 request_id;
|
|
ByteString method;
|
|
URL::URL url;
|
|
HTTP::HeaderMap request_headers;
|
|
ByteBuffer request_body;
|
|
Core::ProxyData proxy_data;
|
|
};
|
|
|
|
struct EnsureConnection {
|
|
URL::URL url;
|
|
CacheLevel cache_level;
|
|
};
|
|
|
|
using Work = Variant<StartRequest, EnsureConnection, Empty>;
|
|
|
|
void worker_do_work(Work);
|
|
|
|
private:
|
|
explicit ConnectionFromClient(NonnullOwnPtr<Core::LocalSocket>);
|
|
|
|
virtual Messages::RequestServer::ConnectNewClientResponse connect_new_client() override;
|
|
virtual Messages::RequestServer::IsSupportedProtocolResponse is_supported_protocol(ByteString const&) override;
|
|
virtual void start_request(i32 request_id, ByteString const&, URL::URL const&, HTTP::HeaderMap const&, ByteBuffer const&, Core::ProxyData const&) override;
|
|
virtual Messages::RequestServer::StopRequestResponse stop_request(i32) override;
|
|
virtual Messages::RequestServer::SetCertificateResponse set_certificate(i32, ByteString const&, ByteString const&) override;
|
|
virtual void ensure_connection(URL::URL const& url, ::RequestServer::CacheLevel const& cache_level) override;
|
|
|
|
virtual Messages::RequestServer::WebsocketConnectResponse websocket_connect(URL::URL const&, ByteString const&, Vector<ByteString> const&, Vector<ByteString> const&, HTTP::HeaderMap const&) override;
|
|
virtual Messages::RequestServer::WebsocketReadyStateResponse websocket_ready_state(i32) override;
|
|
virtual Messages::RequestServer::WebsocketSubprotocolInUseResponse websocket_subprotocol_in_use(i32) override;
|
|
virtual void websocket_send(i32, bool, ByteBuffer const&) override;
|
|
virtual void websocket_close(i32, u16, ByteString const&) override;
|
|
virtual Messages::RequestServer::WebsocketSetCertificateResponse websocket_set_certificate(i32, ByteString const&, ByteString const&) override;
|
|
|
|
virtual void dump_connection_info() override;
|
|
|
|
Threading::MutexProtected<HashMap<i32, OwnPtr<Request>>> m_requests;
|
|
HashMap<i32, RefPtr<WebSocket::WebSocket>> m_websockets;
|
|
|
|
void enqueue(Work);
|
|
|
|
Threading::Mutex m_ipc_mutex;
|
|
};
|
|
|
|
}
|