diff options
author | mhilbrunner <m.hilbrunner@gmail.com> | 2017-12-12 20:02:25 +0100 |
---|---|---|
committer | mhilbrunner <m.hilbrunner@gmail.com> | 2017-12-14 10:59:42 +0100 |
commit | 966c054fc921c7d235dad345baed52de1742c5ed (patch) | |
tree | 48f76ba375e61be7632fcd85e225ef623a909f5d /platform/javascript | |
parent | 55962ce28fec5f06016ed3f66f52e6e84b817dbe (diff) |
HTTP cleanup & better defaults
Diffstat (limited to 'platform/javascript')
-rw-r--r-- | platform/javascript/http_client_javascript.cpp | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/platform/javascript/http_client_javascript.cpp b/platform/javascript/http_client_javascript.cpp index 0b105dcb40..9ce27c9a04 100644 --- a/platform/javascript/http_client_javascript.cpp +++ b/platform/javascript/http_client_javascript.cpp @@ -37,16 +37,31 @@ Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl, WARN_PRINT("Disabling HTTPClient's host verification is not supported for the HTML5 platform, host will be verified"); } + port = p_port; + use_tls = p_ssl; + host = p_host; - if (host.begins_with("http://")) { + + String host_lower = conn_host.to_lower(); + if (host_lower.begins_with("http://")) { host.replace_first("http://", ""); - } else if (host.begins_with("https://")) { + } else if (host_lower.begins_with("https://")) { + use_tls = true; host.replace_first("https://", ""); } + ERR_FAIL_COND_V(host.length() < HOST_MIN_LEN, ERR_INVALID_PARAMETER); + + if (port < 0) { + if (use_tls) { + port = PORT_HTTPS; + } else { + port = PORT_HTTP; + } + } + status = host.is_valid_ip_address() ? STATUS_CONNECTING : STATUS_RESOLVING; - port = p_port; - use_tls = p_ssl; + return OK; } @@ -68,17 +83,7 @@ Error HTTPClient::prepare_request(Method p_method, const String &p_url, const Ve ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(host.empty(), ERR_UNCONFIGURED); ERR_FAIL_COND_V(port < 0, ERR_UNCONFIGURED); - - static const char *_methods[HTTPClient::METHOD_MAX] = { - "GET", - "HEAD", - "POST", - "PUT", - "DELETE", - "OPTIONS", - "TRACE", - "CONNECT" - }; + ERR_FAIL_COND_V(!p_url.begins_with("/"), ERR_INVALID_PARAMETER); String url = (use_tls ? "https://" : "http://") + host + ":" + itos(port) + "/" + p_url; godot_xhr_reset(xhr_id); |