diff options
-rw-r--r-- | doc/classes/HTTPRequest.xml | 18 | ||||
-rw-r--r-- | editor/export_template_manager.cpp | 5 | ||||
-rw-r--r-- | editor/plugins/asset_library_editor_plugin.cpp | 15 | ||||
-rw-r--r-- | scene/main/http_request.cpp | 11 | ||||
-rw-r--r-- | scene/main/http_request.h | 3 |
5 files changed, 49 insertions, 3 deletions
diff --git a/doc/classes/HTTPRequest.xml b/doc/classes/HTTPRequest.xml index aaaf863c69..c92f751c60 100644 --- a/doc/classes/HTTPRequest.xml +++ b/doc/classes/HTTPRequest.xml @@ -208,6 +208,24 @@ Returns [constant OK] if request is successfully created. (Does not imply that the server has responded), [constant ERR_UNCONFIGURED] if not in the tree, [constant ERR_BUSY] if still processing previous request, [constant ERR_INVALID_PARAMETER] if given string is not a valid URL format, or [constant ERR_CANT_CONNECT] if not using thread and the [HTTPClient] cannot connect to host. </description> </method> + <method name="set_http_proxy"> + <return type="void" /> + <argument index="0" name="host" type="String" /> + <argument index="1" name="port" type="int" /> + <description> + Sets the proxy server for HTTP requests. + The proxy server is unset if [code]host[/code] is empty or [code]port[/code] is -1. + </description> + </method> + <method name="set_https_proxy"> + <return type="void" /> + <argument index="0" name="host" type="String" /> + <argument index="1" name="port" type="int" /> + <description> + Sets the proxy server for HTTPS requests. + The proxy server is unset if [code]host[/code] is empty or [code]port[/code] is -1. + </description> + </method> </methods> <members> <member name="accept_gzip" type="bool" setter="set_accept_gzip" getter="is_accepting_gzip" default="true"> diff --git a/editor/export_template_manager.cpp b/editor/export_template_manager.cpp index d9613687f1..7ae7195deb 100644 --- a/editor/export_template_manager.cpp +++ b/editor/export_template_manager.cpp @@ -147,6 +147,11 @@ void ExportTemplateManager::_download_template(const String &p_url, bool p_skip_ download_templates->set_download_file(EditorPaths::get_singleton()->get_cache_dir().plus_file("tmp_templates.tpz")); download_templates->set_use_threads(true); + const String proxy_host = EDITOR_DEF("network/http_proxy/host", ""); + const int proxy_port = EDITOR_DEF("network/http_proxy/port", -1); + download_templates->set_http_proxy(proxy_host, proxy_port); + download_templates->set_https_proxy(proxy_host, proxy_port); + Error err = download_templates->request(p_url); if (err != OK) { _set_current_progress_status(TTR("Error requesting URL:") + " " + p_url, true); diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp index 951af92467..994e89d96f 100644 --- a/editor/plugins/asset_library_editor_plugin.cpp +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -39,6 +39,15 @@ #include "editor/editor_settings.h" #include "editor/project_settings_editor.h" +static inline void setup_http_request(HTTPRequest *request) { + request->set_use_threads(EDITOR_DEF("asset_library/use_threads", true)); + + const String proxy_host = EDITOR_DEF("network/http_proxy/host", ""); + const int proxy_port = EDITOR_DEF("network/http_proxy/port", -1); + request->set_http_proxy(proxy_host, proxy_port); + request->set_https_proxy(proxy_host, proxy_port); +} + void EditorAssetLibraryItem::configure(const String &p_title, int p_asset_id, const String &p_category, int p_category_id, const String &p_author, int p_author_id, const String &p_cost) { title->set_text(p_title); asset_id = p_asset_id; @@ -534,7 +543,7 @@ EditorAssetLibraryItemDownload::EditorAssetLibraryItemDownload() { download = memnew(HTTPRequest); add_child(download); download->connect("request_completed", callable_mp(this, &EditorAssetLibraryItemDownload::_http_download_completed)); - download->set_use_threads(EDITOR_DEF("asset_library/use_threads", true)); + setup_http_request(download); download_error = memnew(AcceptDialog); add_child(download_error); @@ -869,7 +878,7 @@ void EditorAssetLibrary::_request_image(ObjectID p_for, String p_image_url, Imag iq.image_index = p_image_index; iq.image_type = p_type; iq.request = memnew(HTTPRequest); - iq.request->set_use_threads(EDITOR_DEF("asset_library/use_threads", true)); + setup_http_request(iq.request); iq.target = p_for; iq.queue_id = ++last_queue_id; @@ -1476,7 +1485,7 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { request = memnew(HTTPRequest); add_child(request); - request->set_use_threads(EDITOR_DEF("asset_library/use_threads", true)); + setup_http_request(request); request->connect("request_completed", callable_mp(this, &EditorAssetLibrary::_http_request_completed)); last_queue_id = 0; diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp index 4797729871..2dbfb43ad3 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(); }; |