ladybird/Ladybird/Qt/RequestManagerQt.h
Shannon Booth e800605ad3 AK+LibURL: Move AK::URL into a new URL library
This URL library ends up being a relatively fundamental base library of
the system, as LibCore depends on LibURL.

This change has two main benefits:
 * Moving AK back more towards being an agnostic library that can
   be used between the kernel and userspace. URL has never really fit
   that description - and is not used in the kernel.
 * URL _should_ depend on LibUnicode, as it needs punnycode support.
   However, it's not really possible to do this inside of AK as it can't
   depend on any external library. This change brings us a little closer
   to being able to do that, but unfortunately we aren't there quite
   yet, as the code generators depend on LibCore.
2024-03-18 14:06:28 -04:00

64 lines
1.9 KiB
C++

/*
* 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>
namespace Ladybird {
class RequestManagerQt
: public QObject
, public Web::ResourceLoaderConnector {
Q_OBJECT
public:
static NonnullRefPtr<RequestManagerQt> create()
{
return adopt_ref(*new RequestManagerQt());
}
virtual ~RequestManagerQt() override { }
virtual void prefetch_dns(URL::URL const&) override { }
virtual void preconnect(URL::URL const&) override { }
virtual RefPtr<Web::ResourceLoaderConnectorRequest> start_request(ByteString const& method, URL::URL const&, HashMap<ByteString, ByteString> const& request_headers, ReadonlyBytes request_body, Core::ProxyData const&) override;
virtual RefPtr<Web::WebSockets::WebSocketClientSocket> websocket_connect(const URL::URL&, ByteString const& origin, Vector<ByteString> const& protocols) override;
private slots:
void reply_finished(QNetworkReply*);
private:
RequestManagerQt();
class Request
: public Web::ResourceLoaderConnectorRequest {
public:
static ErrorOr<NonnullRefPtr<Request>> create(QNetworkAccessManager& qnam, ByteString const& method, URL::URL const& url, HashMap<ByteString, ByteString> const& request_headers, ReadonlyBytes request_body, Core::ProxyData const&);
virtual ~Request() override;
virtual void set_should_buffer_all_input(bool) override { }
virtual bool stop() override { return false; }
virtual void stream_into(Stream&) override { }
void did_finish();
QNetworkReply& reply() { return m_reply; }
private:
Request(QNetworkReply&);
QNetworkReply& m_reply;
};
HashMap<QNetworkReply*, NonnullRefPtr<Request>> m_pending;
QNetworkAccessManager* m_qnam { nullptr };
};
}