diff options
-rw-r--r-- | Userland/Applications/Browser/DownloadWidget.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibIPC/Decoder.cpp | 11 | ||||
-rw-r--r-- | Userland/Libraries/LibIPC/Encoder.cpp | 9 | ||||
-rw-r--r-- | Userland/Libraries/LibProtocol/RequestClient.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibProtocol/RequestClient.h | 4 | ||||
-rw-r--r-- | Userland/Services/RequestServer/ConnectionFromClient.cpp | 5 | ||||
-rw-r--r-- | Userland/Services/RequestServer/ConnectionFromClient.h | 4 | ||||
-rw-r--r-- | Userland/Services/RequestServer/GeminiProtocol.cpp | 4 | ||||
-rw-r--r-- | Userland/Services/RequestServer/GeminiProtocol.h | 2 | ||||
-rw-r--r-- | Userland/Services/RequestServer/HttpCommon.h | 6 | ||||
-rw-r--r-- | Userland/Services/RequestServer/HttpProtocol.cpp | 4 | ||||
-rw-r--r-- | Userland/Services/RequestServer/HttpProtocol.h | 2 | ||||
-rw-r--r-- | Userland/Services/RequestServer/HttpsProtocol.cpp | 4 | ||||
-rw-r--r-- | Userland/Services/RequestServer/HttpsProtocol.h | 2 | ||||
-rw-r--r-- | Userland/Services/RequestServer/Protocol.h | 3 | ||||
-rw-r--r-- | Userland/Services/RequestServer/RequestServer.ipc | 2 |
16 files changed, 52 insertions, 24 deletions
diff --git a/Userland/Applications/Browser/DownloadWidget.cpp b/Userland/Applications/Browser/DownloadWidget.cpp index 3b173ce0f2..cfd2c82f8b 100644 --- a/Userland/Applications/Browser/DownloadWidget.cpp +++ b/Userland/Applications/Browser/DownloadWidget.cpp @@ -8,7 +8,7 @@ #include "DownloadWidget.h" #include <AK/NumberFormat.h> #include <AK/StringBuilder.h> -#include <LibConfig/Client.h> +#include <LibCore/Proxy.h> #include <LibCore/StandardPaths.h> #include <LibCore/Stream.h> #include <LibDesktop/Launcher.h> @@ -20,9 +20,11 @@ #include <LibGUI/MessageBox.h> #include <LibGUI/Progressbar.h> #include <LibGUI/Window.h> -#include <LibProtocol/RequestClient.h> #include <LibWeb/Loader/ResourceLoader.h> +#include <LibConfig/Client.h> +#include <LibProtocol/RequestClient.h> + namespace Browser { DownloadWidget::DownloadWidget(const URL& url) diff --git a/Userland/Libraries/LibIPC/Decoder.cpp b/Userland/Libraries/LibIPC/Decoder.cpp index 0002acf7d5..731a5fb669 100644 --- a/Userland/Libraries/LibIPC/Decoder.cpp +++ b/Userland/Libraries/LibIPC/Decoder.cpp @@ -8,6 +8,7 @@ #include <AK/URL.h> #include <LibCore/AnonymousBuffer.h> #include <LibCore/DateTime.h> +#include <LibCore/Proxy.h> #include <LibIPC/Decoder.h> #include <LibIPC/Dictionary.h> #include <LibIPC/File.h> @@ -185,4 +186,14 @@ ErrorOr<void> decode(Decoder& decoder, Core::DateTime& datetime) return {}; } +ErrorOr<void> decode(Decoder& decoder, Core::ProxyData& data) +{ + UnderlyingType<decltype(data.type)> type; + TRY(decoder.decode(type)); + data.type = static_cast<Core::ProxyData::Type>(type); + TRY(decoder.decode(data.host_ipv4)); + TRY(decoder.decode(data.port)); + return {}; +} + } diff --git a/Userland/Libraries/LibIPC/Encoder.cpp b/Userland/Libraries/LibIPC/Encoder.cpp index 13dc4922c6..430659dd0e 100644 --- a/Userland/Libraries/LibIPC/Encoder.cpp +++ b/Userland/Libraries/LibIPC/Encoder.cpp @@ -11,6 +11,7 @@ #include <AK/URL.h> #include <LibCore/AnonymousBuffer.h> #include <LibCore/DateTime.h> +#include <LibCore/Proxy.h> #include <LibIPC/Dictionary.h> #include <LibIPC/Encoder.h> #include <LibIPC/File.h> @@ -203,4 +204,12 @@ bool encode(Encoder& encoder, Core::DateTime const& datetime) return true; } +bool encode(Encoder& encoder, Core::ProxyData const& proxy) +{ + encoder << to_underlying(proxy.type); + encoder << proxy.host_ipv4; + encoder << proxy.port; + return true; +} + } diff --git a/Userland/Libraries/LibProtocol/RequestClient.cpp b/Userland/Libraries/LibProtocol/RequestClient.cpp index 3851f6b217..8087b1dd5f 100644 --- a/Userland/Libraries/LibProtocol/RequestClient.cpp +++ b/Userland/Libraries/LibProtocol/RequestClient.cpp @@ -21,7 +21,7 @@ void RequestClient::ensure_connection(URL const& url, ::RequestServer::CacheLeve } template<typename RequestHashMapTraits> -RefPtr<Request> RequestClient::start_request(String const& method, URL const& url, HashMap<String, String, RequestHashMapTraits> const& request_headers, ReadonlyBytes request_body) +RefPtr<Request> RequestClient::start_request(String const& method, URL const& url, HashMap<String, String, RequestHashMapTraits> const& request_headers, ReadonlyBytes request_body, Core::ProxyData const& proxy_data) { IPC::Dictionary header_dictionary; for (auto& it : request_headers) @@ -31,7 +31,7 @@ RefPtr<Request> RequestClient::start_request(String const& method, URL const& ur if (body_result.is_error()) return nullptr; - auto response = IPCProxy::start_request(method, url, header_dictionary, body_result.release_value()); + auto response = IPCProxy::start_request(method, url, header_dictionary, body_result.release_value(), proxy_data); auto request_id = response.request_id(); if (request_id < 0 || !response.response_fd().has_value()) return nullptr; @@ -91,5 +91,5 @@ void RequestClient::certificate_requested(i32 request_id) } -template RefPtr<Protocol::Request> Protocol::RequestClient::start_request(String const& method, URL const&, HashMap<String, String> const& request_headers, ReadonlyBytes request_body); -template RefPtr<Protocol::Request> Protocol::RequestClient::start_request(String const& method, URL const&, HashMap<String, String, CaseInsensitiveStringTraits> const& request_headers, ReadonlyBytes request_body); +template RefPtr<Protocol::Request> Protocol::RequestClient::start_request(String const& method, URL const&, HashMap<String, String> const& request_headers, ReadonlyBytes request_body, Core::ProxyData const&); +template RefPtr<Protocol::Request> Protocol::RequestClient::start_request(String const& method, URL const&, HashMap<String, String, CaseInsensitiveStringTraits> const& request_headers, ReadonlyBytes request_body, Core::ProxyData const&); diff --git a/Userland/Libraries/LibProtocol/RequestClient.h b/Userland/Libraries/LibProtocol/RequestClient.h index 190a766a26..d44d3a9f4b 100644 --- a/Userland/Libraries/LibProtocol/RequestClient.h +++ b/Userland/Libraries/LibProtocol/RequestClient.h @@ -7,6 +7,8 @@ #pragma once #include <AK/HashMap.h> +// Need to include this before RequestClientEndpoint.h as that one includes LibIPC/(De En)coder.h, which would bomb if included before this. +#include <LibCore/Proxy.h> #include <LibIPC/ConnectionToServer.h> #include <RequestServer/RequestClientEndpoint.h> #include <RequestServer/RequestServerEndpoint.h> @@ -22,7 +24,7 @@ class RequestClient final public: template<typename RequestHashMapTraits = Traits<String>> - RefPtr<Request> start_request(String const& method, URL const&, HashMap<String, String, RequestHashMapTraits> const& request_headers = {}, ReadonlyBytes request_body = {}); + RefPtr<Request> start_request(String const& method, URL const&, HashMap<String, String, RequestHashMapTraits> const& request_headers = {}, ReadonlyBytes request_body = {}, Core::ProxyData const& = {}); void ensure_connection(URL const&, ::RequestServer::CacheLevel); diff --git a/Userland/Services/RequestServer/ConnectionFromClient.cpp b/Userland/Services/RequestServer/ConnectionFromClient.cpp index dd2937e61d..34ac465d54 100644 --- a/Userland/Services/RequestServer/ConnectionFromClient.cpp +++ b/Userland/Services/RequestServer/ConnectionFromClient.cpp @@ -6,6 +6,7 @@ #include <AK/Badge.h> #include <AK/NonnullOwnPtr.h> +#include <LibCore/Proxy.h> #include <RequestServer/ConnectionFromClient.h> #include <RequestServer/Protocol.h> #include <RequestServer/Request.h> @@ -35,7 +36,7 @@ Messages::RequestServer::IsSupportedProtocolResponse ConnectionFromClient::is_su return supported; } -Messages::RequestServer::StartRequestResponse ConnectionFromClient::start_request(String const& method, URL const& url, IPC::Dictionary const& request_headers, ByteBuffer const& request_body) +Messages::RequestServer::StartRequestResponse ConnectionFromClient::start_request(String const& method, URL const& url, IPC::Dictionary const& request_headers, ByteBuffer const& request_body, Core::ProxyData const& proxy_data) { if (!url.is_valid()) { dbgln("StartRequest: Invalid URL requested: '{}'", url); @@ -46,7 +47,7 @@ Messages::RequestServer::StartRequestResponse ConnectionFromClient::start_reques dbgln("StartRequest: No protocol handler for URL: '{}'", url); return { -1, Optional<IPC::File> {} }; } - auto request = protocol->start_request(*this, method, url, request_headers.entries(), request_body); + auto request = protocol->start_request(*this, method, url, request_headers.entries(), request_body, proxy_data); if (!request) { dbgln("StartRequest: Protocol handler failed to start request: '{}'", url); return { -1, Optional<IPC::File> {} }; diff --git a/Userland/Services/RequestServer/ConnectionFromClient.h b/Userland/Services/RequestServer/ConnectionFromClient.h index a22b52ea81..3fca6387d2 100644 --- a/Userland/Services/RequestServer/ConnectionFromClient.h +++ b/Userland/Services/RequestServer/ConnectionFromClient.h @@ -7,6 +7,8 @@ #pragma once #include <AK/HashMap.h> +// Need to include this before RequestClientEndpoint.h as that one includes LibIPC/(De En)coder.h, which would bomb if included before this. +#include <LibCore/Proxy.h> #include <LibIPC/ConnectionFromClient.h> #include <RequestServer/Forward.h> #include <RequestServer/RequestClientEndpoint.h> @@ -32,7 +34,7 @@ private: explicit ConnectionFromClient(NonnullOwnPtr<Core::Stream::LocalSocket>); virtual Messages::RequestServer::IsSupportedProtocolResponse is_supported_protocol(String const&) override; - virtual Messages::RequestServer::StartRequestResponse start_request(String const&, URL const&, IPC::Dictionary const&, ByteBuffer const&) override; + virtual Messages::RequestServer::StartRequestResponse start_request(String const&, URL const&, IPC::Dictionary const&, ByteBuffer const&, Core::ProxyData const&) override; virtual Messages::RequestServer::StopRequestResponse stop_request(i32) override; virtual Messages::RequestServer::SetCertificateResponse set_certificate(i32, String const&, String const&) override; virtual void ensure_connection(URL const& url, ::RequestServer::CacheLevel const& cache_level) override; diff --git a/Userland/Services/RequestServer/GeminiProtocol.cpp b/Userland/Services/RequestServer/GeminiProtocol.cpp index befe40903d..3b60b39644 100644 --- a/Userland/Services/RequestServer/GeminiProtocol.cpp +++ b/Userland/Services/RequestServer/GeminiProtocol.cpp @@ -17,7 +17,7 @@ GeminiProtocol::GeminiProtocol() { } -OwnPtr<Request> GeminiProtocol::start_request(ConnectionFromClient& client, String const&, const URL& url, HashMap<String, String> const&, ReadonlyBytes) +OwnPtr<Request> GeminiProtocol::start_request(ConnectionFromClient& client, String const&, const URL& url, HashMap<String, String> const&, ReadonlyBytes, Core::ProxyData proxy_data) { Gemini::GeminiRequest request; request.set_url(url); @@ -31,7 +31,7 @@ OwnPtr<Request> GeminiProtocol::start_request(ConnectionFromClient& client, Stri auto protocol_request = GeminiRequest::create_with_job({}, client, *job, move(output_stream)); protocol_request->set_request_fd(pipe_result.value().read_fd); - ConnectionCache::get_or_create_connection(ConnectionCache::g_tls_connection_cache, url, *job); + ConnectionCache::get_or_create_connection(ConnectionCache::g_tls_connection_cache, url, *job, proxy_data); return protocol_request; } diff --git a/Userland/Services/RequestServer/GeminiProtocol.h b/Userland/Services/RequestServer/GeminiProtocol.h index 4ecf29a070..6830b50d90 100644 --- a/Userland/Services/RequestServer/GeminiProtocol.h +++ b/Userland/Services/RequestServer/GeminiProtocol.h @@ -15,7 +15,7 @@ public: GeminiProtocol(); virtual ~GeminiProtocol() override = default; - virtual OwnPtr<Request> start_request(ConnectionFromClient&, String const& method, const URL&, HashMap<String, String> const&, ReadonlyBytes body) override; + virtual OwnPtr<Request> start_request(ConnectionFromClient&, String const& method, const URL&, HashMap<String, String> const&, ReadonlyBytes body, Core::ProxyData proxy_data = {}) override; }; } diff --git a/Userland/Services/RequestServer/HttpCommon.h b/Userland/Services/RequestServer/HttpCommon.h index 7ea0a18573..57b10dee5f 100644 --- a/Userland/Services/RequestServer/HttpCommon.h +++ b/Userland/Services/RequestServer/HttpCommon.h @@ -61,7 +61,7 @@ void init(TSelf* self, TJob job) } template<typename TBadgedProtocol, typename TPipeResult> -OwnPtr<Request> start_request(TBadgedProtocol&& protocol, ConnectionFromClient& client, String const& method, const URL& url, HashMap<String, String> const& headers, ReadonlyBytes body, TPipeResult&& pipe_result) +OwnPtr<Request> start_request(TBadgedProtocol&& protocol, ConnectionFromClient& client, String const& method, const URL& url, HashMap<String, String> const& headers, ReadonlyBytes body, TPipeResult&& pipe_result, Core::ProxyData proxy_data = {}) { using TJob = typename TBadgedProtocol::Type::JobType; using TRequest = typename TBadgedProtocol::Type::RequestType; @@ -89,9 +89,9 @@ OwnPtr<Request> start_request(TBadgedProtocol&& protocol, ConnectionFromClient& protocol_request->set_request_fd(pipe_result.value().read_fd); if constexpr (IsSame<typename TBadgedProtocol::Type, HttpsProtocol>) - ConnectionCache::get_or_create_connection(ConnectionCache::g_tls_connection_cache, url, *job); + ConnectionCache::get_or_create_connection(ConnectionCache::g_tls_connection_cache, url, *job, proxy_data); else - ConnectionCache::get_or_create_connection(ConnectionCache::g_tcp_connection_cache, url, *job); + ConnectionCache::get_or_create_connection(ConnectionCache::g_tcp_connection_cache, url, *job, proxy_data); return protocol_request; } diff --git a/Userland/Services/RequestServer/HttpProtocol.cpp b/Userland/Services/RequestServer/HttpProtocol.cpp index fdfc4971d5..f0a7354b5c 100644 --- a/Userland/Services/RequestServer/HttpProtocol.cpp +++ b/Userland/Services/RequestServer/HttpProtocol.cpp @@ -22,9 +22,9 @@ HttpProtocol::HttpProtocol() { } -OwnPtr<Request> HttpProtocol::start_request(ConnectionFromClient& client, String const& method, const URL& url, HashMap<String, String> const& headers, ReadonlyBytes body) +OwnPtr<Request> HttpProtocol::start_request(ConnectionFromClient& client, String const& method, const URL& url, HashMap<String, String> const& headers, ReadonlyBytes body, Core::ProxyData proxy_data) { - return Detail::start_request(Badge<HttpProtocol> {}, client, method, url, headers, body, get_pipe_for_request()); + return Detail::start_request(Badge<HttpProtocol> {}, client, method, url, headers, body, get_pipe_for_request(), proxy_data); } } diff --git a/Userland/Services/RequestServer/HttpProtocol.h b/Userland/Services/RequestServer/HttpProtocol.h index 012e6bc033..019978f3f6 100644 --- a/Userland/Services/RequestServer/HttpProtocol.h +++ b/Userland/Services/RequestServer/HttpProtocol.h @@ -27,7 +27,7 @@ public: HttpProtocol(); ~HttpProtocol() override = default; - virtual OwnPtr<Request> start_request(ConnectionFromClient&, String const& method, const URL&, HashMap<String, String> const& headers, ReadonlyBytes body) override; + virtual OwnPtr<Request> start_request(ConnectionFromClient&, String const& method, const URL&, HashMap<String, String> const& headers, ReadonlyBytes body, Core::ProxyData proxy_data = {}) override; }; } diff --git a/Userland/Services/RequestServer/HttpsProtocol.cpp b/Userland/Services/RequestServer/HttpsProtocol.cpp index 0580bff44b..c7df2d5402 100644 --- a/Userland/Services/RequestServer/HttpsProtocol.cpp +++ b/Userland/Services/RequestServer/HttpsProtocol.cpp @@ -22,9 +22,9 @@ HttpsProtocol::HttpsProtocol() { } -OwnPtr<Request> HttpsProtocol::start_request(ConnectionFromClient& client, String const& method, const URL& url, HashMap<String, String> const& headers, ReadonlyBytes body) +OwnPtr<Request> HttpsProtocol::start_request(ConnectionFromClient& client, String const& method, const URL& url, HashMap<String, String> const& headers, ReadonlyBytes body, Core::ProxyData proxy_data) { - return Detail::start_request(Badge<HttpsProtocol> {}, client, method, url, headers, body, get_pipe_for_request()); + return Detail::start_request(Badge<HttpsProtocol> {}, client, method, url, headers, body, get_pipe_for_request(), proxy_data); } } diff --git a/Userland/Services/RequestServer/HttpsProtocol.h b/Userland/Services/RequestServer/HttpsProtocol.h index c1083b684a..934ce373d1 100644 --- a/Userland/Services/RequestServer/HttpsProtocol.h +++ b/Userland/Services/RequestServer/HttpsProtocol.h @@ -27,7 +27,7 @@ public: HttpsProtocol(); ~HttpsProtocol() override = default; - virtual OwnPtr<Request> start_request(ConnectionFromClient&, String const& method, const URL&, HashMap<String, String> const& headers, ReadonlyBytes body) override; + virtual OwnPtr<Request> start_request(ConnectionFromClient&, String const& method, const URL&, HashMap<String, String> const& headers, ReadonlyBytes body, Core::ProxyData proxy_data = {}) override; }; } diff --git a/Userland/Services/RequestServer/Protocol.h b/Userland/Services/RequestServer/Protocol.h index e0ab1493fc..c3d86d896a 100644 --- a/Userland/Services/RequestServer/Protocol.h +++ b/Userland/Services/RequestServer/Protocol.h @@ -8,6 +8,7 @@ #include <AK/RefPtr.h> #include <AK/URL.h> +#include <LibCore/Proxy.h> #include <RequestServer/Forward.h> namespace RequestServer { @@ -17,7 +18,7 @@ public: virtual ~Protocol(); String const& name() const { return m_name; } - virtual OwnPtr<Request> start_request(ConnectionFromClient&, String const& method, const URL&, HashMap<String, String> const& headers, ReadonlyBytes body) = 0; + virtual OwnPtr<Request> start_request(ConnectionFromClient&, String const& method, const URL&, HashMap<String, String> const& headers, ReadonlyBytes body, Core::ProxyData proxy_data = {}) = 0; static Protocol* find_by_name(String const&); diff --git a/Userland/Services/RequestServer/RequestServer.ipc b/Userland/Services/RequestServer/RequestServer.ipc index b02be37eb6..7f6d89c0c8 100644 --- a/Userland/Services/RequestServer/RequestServer.ipc +++ b/Userland/Services/RequestServer/RequestServer.ipc @@ -6,7 +6,7 @@ endpoint RequestServer // Test if a specific protocol is supported, e.g "http" is_supported_protocol(String protocol) => (bool supported) - start_request(String method, URL url, IPC::Dictionary request_headers, ByteBuffer request_body) => (i32 request_id, Optional<IPC::File> response_fd) + start_request(String method, URL url, IPC::Dictionary request_headers, ByteBuffer request_body, Core::ProxyData proxy_data) => (i32 request_id, Optional<IPC::File> response_fd) stop_request(i32 request_id) => (bool success) set_certificate(i32 request_id, String certificate, String key) => (bool success) |