mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 05:25:32 +03:00
LibWeb will need to use unbuffered requests to support server-sent events. Connection for such events remain open and the remote end sends data as HTTP bodies at its leisure. The browser needs to be able to handle this data as it arrives, as the request essentially never finishes. To support this, this make Protocol::Request operate in one of two modes: buffered or unbuffered. The existing mechanism for setting up a buffered request was a bit awkward; you had to set specific callbacks, but be sure not to set some others, and then set a flag. The new mechanism is to set the mode and the callbacks that the mode needs in one API.
67 lines
2.2 KiB
C++
67 lines
2.2 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_buffered_request_finished_callback(Protocol::Request::BufferedRequestFinished) override;
|
|
virtual void set_unbuffered_request_callbacks(Protocol::Request::HeadersReceived, Protocol::Request::DataReceived, Protocol::Request::RequestFinished) override;
|
|
virtual bool stop() override { return false; }
|
|
|
|
void did_finish();
|
|
|
|
QNetworkReply& reply() { return m_reply; }
|
|
|
|
private:
|
|
Request(QNetworkReply&);
|
|
|
|
QNetworkReply& m_reply;
|
|
|
|
Protocol::Request::BufferedRequestFinished on_buffered_request_finish;
|
|
};
|
|
|
|
HashMap<QNetworkReply*, NonnullRefPtr<Request>> m_pending;
|
|
QNetworkAccessManager* m_qnam { nullptr };
|
|
};
|
|
|
|
}
|