2022-07-05 19:13:38 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <LibWeb/Loader/ResourceLoader.h>
|
|
|
|
#include <QtNetwork/QNetworkAccessManager>
|
|
|
|
#include <QtNetwork/QNetworkReply>
|
|
|
|
|
2023-08-02 17:52:59 +00:00
|
|
|
namespace Ladybird {
|
|
|
|
|
2022-07-05 19:13:38 +00:00
|
|
|
class RequestManagerQt
|
|
|
|
: public QObject
|
|
|
|
, public Web::ResourceLoaderConnector {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2024-07-10 11:50:21 +00:00
|
|
|
static NonnullRefPtr<RequestManagerQt> create(Vector<ByteString> const& certificate_paths)
|
2022-07-05 19:13:38 +00:00
|
|
|
{
|
2024-07-10 11:50:21 +00:00
|
|
|
return adopt_ref(*new RequestManagerQt(certificate_paths));
|
2022-07-05 19:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~RequestManagerQt() override { }
|
|
|
|
|
2024-03-18 03:22:27 +00:00
|
|
|
virtual void prefetch_dns(URL::URL const&) override { }
|
|
|
|
virtual void preconnect(URL::URL const&) override { }
|
2022-07-05 19:13:38 +00:00
|
|
|
|
2024-06-09 11:46:04 +00:00
|
|
|
virtual RefPtr<Web::ResourceLoaderConnectorRequest> start_request(ByteString const& method, URL::URL const&, HTTP::HeaderMap const& request_headers, ReadonlyBytes request_body, Core::ProxyData const&) override;
|
2024-03-18 03:22:27 +00:00
|
|
|
virtual RefPtr<Web::WebSockets::WebSocketClientSocket> websocket_connect(const URL::URL&, ByteString const& origin, Vector<ByteString> const& protocols) override;
|
2022-07-05 19:13:38 +00:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void reply_finished(QNetworkReply*);
|
|
|
|
|
|
|
|
private:
|
2024-07-10 11:50:21 +00:00
|
|
|
explicit RequestManagerQt(Vector<ByteString> const& certificate_paths);
|
2022-07-05 19:13:38 +00:00
|
|
|
|
|
|
|
class Request
|
|
|
|
: public Web::ResourceLoaderConnectorRequest {
|
|
|
|
public:
|
2024-06-09 11:46:04 +00:00
|
|
|
static ErrorOr<NonnullRefPtr<Request>> create(QNetworkAccessManager& qnam, ByteString const& method, URL::URL const& url, HTTP::HeaderMap const& request_headers, ReadonlyBytes request_body, Core::ProxyData const&);
|
2022-07-05 19:13:38 +00:00
|
|
|
|
|
|
|
virtual ~Request() override;
|
|
|
|
|
2024-08-07 03:51:20 +00:00
|
|
|
virtual void set_buffered_request_finished_callback(Requests::Request::BufferedRequestFinished) override;
|
|
|
|
virtual void set_unbuffered_request_callbacks(Requests::Request::HeadersReceived, Requests::Request::DataReceived, Requests::Request::RequestFinished) override;
|
2022-07-05 19:13:38 +00:00
|
|
|
virtual bool stop() override { return false; }
|
|
|
|
|
|
|
|
void did_finish();
|
|
|
|
|
|
|
|
QNetworkReply& reply() { return m_reply; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Request(QNetworkReply&);
|
|
|
|
|
|
|
|
QNetworkReply& m_reply;
|
2024-05-24 15:37:02 +00:00
|
|
|
|
2024-08-07 03:51:20 +00:00
|
|
|
Requests::Request::BufferedRequestFinished on_buffered_request_finish;
|
2022-07-05 19:13:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
HashMap<QNetworkReply*, NonnullRefPtr<Request>> m_pending;
|
|
|
|
QNetworkAccessManager* m_qnam { nullptr };
|
|
|
|
};
|
2023-08-02 17:52:59 +00:00
|
|
|
|
|
|
|
}
|