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.
This commit is contained in:
parent
f1e3c87244
commit
5912dd2964
|
@ -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">
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
@ -533,7 +542,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);
|
||||
|
@ -868,7 +877,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;
|
||||
|
@ -1475,7 +1484,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;
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue