From 5912dd296487242b528836efc9dd045356ec3593 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Thu, 9 Dec 2021 11:34:32 +0800 Subject: Add proxy support for the editor * Adds proxy support for `HTTPRequest`. * Adds `network/http_proxy/{host,port}` editor settings. * Labeled as "HTTP Proxy" and it will be used for both HTTP and HTTPS requests. This is the same convention as seen in Android Studio's proxy settings. * Makes Asset Library and Export Template Manager use proxy according to the editor settings. --- scene/main/http_request.cpp | 11 +++++++++++ scene/main/http_request.h | 3 +++ 2 files changed, 14 insertions(+) (limited to 'scene/main') diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp index a4fcc04e20..c9fd135b2b 100644 --- a/scene/main/http_request.cpp +++ b/scene/main/http_request.cpp @@ -554,6 +554,14 @@ int HTTPRequest::get_body_size() const { return body_len; } +void HTTPRequest::set_http_proxy(const String &p_host, int p_port) { + client->set_http_proxy(p_host, p_port); +} + +void HTTPRequest::set_https_proxy(const String &p_host, int p_port) { + client->set_https_proxy(p_host, p_port); +} + void HTTPRequest::set_timeout(int p_timeout) { ERR_FAIL_COND(p_timeout < 0); timeout = p_timeout; @@ -602,6 +610,9 @@ void HTTPRequest::_bind_methods() { ClassDB::bind_method(D_METHOD("set_download_chunk_size", "chunk_size"), &HTTPRequest::set_download_chunk_size); ClassDB::bind_method(D_METHOD("get_download_chunk_size"), &HTTPRequest::get_download_chunk_size); + ClassDB::bind_method(D_METHOD("set_http_proxy", "host", "port"), &HTTPRequest::set_http_proxy); + ClassDB::bind_method(D_METHOD("set_https_proxy", "host", "port"), &HTTPRequest::set_https_proxy); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "download_file", PROPERTY_HINT_FILE), "set_download_file", "get_download_file"); ADD_PROPERTY(PropertyInfo(Variant::INT, "download_chunk_size", PROPERTY_HINT_RANGE, "256,16777216"), "set_download_chunk_size", "get_download_chunk_size"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_threads"), "set_use_threads", "is_using_threads"); diff --git a/scene/main/http_request.h b/scene/main/http_request.h index 673cf3a740..38c2f704ec 100644 --- a/scene/main/http_request.h +++ b/scene/main/http_request.h @@ -154,6 +154,9 @@ public: int get_downloaded_bytes() const; int get_body_size() const; + void set_http_proxy(const String &p_host, int p_port); + void set_https_proxy(const String &p_host, int p_port); + HTTPRequest(); ~HTTPRequest(); }; -- cgit v1.2.3