diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2020-05-14 13:23:58 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2020-05-14 16:54:55 +0200 |
commit | 0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a (patch) | |
tree | a27e497da7104dd0a64f98a04fa3067668735e91 /scene/main/http_request.cpp | |
parent | 710b34b70227becdc652b4ae027fe0ac47409642 (diff) | |
download | redot-engine-0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a.tar.gz |
Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks
Which means that reduz' beloved style which we all became used to
will now be changed automatically to remove the first empty line.
This makes us lean closer to 1TBS (the one true brace style) instead
of hybridating it with some Allman-inspired spacing.
There's still the case of braces around single-statement blocks that
needs to be addressed (but clang-format can't help with that, but
clang-tidy may if we agree about it).
Part of #33027.
Diffstat (limited to 'scene/main/http_request.cpp')
-rw-r--r-- | scene/main/http_request.cpp | 38 |
1 files changed, 0 insertions, 38 deletions
diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp index dc0da015ac..d9280a96d2 100644 --- a/scene/main/http_request.cpp +++ b/scene/main/http_request.cpp @@ -34,12 +34,10 @@ void HTTPRequest::_redirect_request(const String &p_new_url) { } Error HTTPRequest::_request() { - return client->connect_to_host(url, port, use_ssl, validate_ssl); } Error HTTPRequest::_parse_url(const String &p_url) { - url = p_url; use_ssl = false; @@ -85,7 +83,6 @@ Error HTTPRequest::_parse_url(const String &p_url) { } Error HTTPRequest::request(const String &p_url, const Vector<String> &p_custom_headers, bool p_ssl_validate_domain, HTTPClient::Method p_method, const String &p_request_data) { - ERR_FAIL_COND_V(!is_inside_tree(), ERR_UNCONFIGURED); ERR_FAIL_COND_V_MSG(requesting, ERR_BUSY, "HTTPRequest is processing a request. Wait for completion or cancel it before attempting a new one."); @@ -109,7 +106,6 @@ Error HTTPRequest::request(const String &p_url, const Vector<String> &p_custom_h requesting = true; if (use_threads) { - thread_done = false; thread_request_quit = false; client->set_blocking_mode(true); @@ -129,7 +125,6 @@ Error HTTPRequest::request(const String &p_url, const Vector<String> &p_custom_h } void HTTPRequest::_thread_func(void *p_userdata) { - HTTPRequest *hr = (HTTPRequest *)p_userdata; Error err = hr->_request(); @@ -138,7 +133,6 @@ void HTTPRequest::_thread_func(void *p_userdata) { hr->call_deferred("_request_done", RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray()); } else { while (!hr->thread_request_quit) { - bool exit = hr->_update_connection(); if (exit) break; @@ -150,7 +144,6 @@ void HTTPRequest::_thread_func(void *p_userdata) { } void HTTPRequest::cancel_request() { - timer->stop(); if (!requesting) @@ -178,7 +171,6 @@ void HTTPRequest::cancel_request() { } bool HTTPRequest::_handle_response(bool *ret_value) { - if (!client->has_response()) { call_deferred("_request_done", RESULT_NO_RESPONSE, 0, PackedStringArray(), PackedByteArray()); *ret_value = true; @@ -199,7 +191,6 @@ bool HTTPRequest::_handle_response(bool *ret_value) { // Handle redirect if (max_redirects >= 0 && redirections >= max_redirects) { - call_deferred("_request_done", RESULT_REDIRECT_LIMIT_REACHED, response_code, response_headers, PackedByteArray()); *ret_value = true; return true; @@ -243,7 +234,6 @@ bool HTTPRequest::_handle_response(bool *ret_value) { } bool HTTPRequest::_update_connection() { - switch (client->get_status()) { case HTTPClient::STATUS_DISCONNECTED: { call_deferred("_request_done", RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray()); @@ -265,17 +255,13 @@ bool HTTPRequest::_update_connection() { return false; } break; // Connecting to IP case HTTPClient::STATUS_CANT_CONNECT: { - call_deferred("_request_done", RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray()); return true; } break; case HTTPClient::STATUS_CONNECTED: { - if (request_sent) { - if (!got_response) { - // No body bool ret_value; @@ -315,16 +301,13 @@ bool HTTPRequest::_update_connection() { } break; // Request in progress case HTTPClient::STATUS_BODY: { - if (!got_response) { - bool ret_value; if (_handle_response(&ret_value)) return ret_value; if (!client->is_response_chunked() && client->get_response_body_length() == 0) { - call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, PackedByteArray()); return true; } @@ -341,7 +324,6 @@ bool HTTPRequest::_update_connection() { if (download_to_file != String()) { file = FileAccess::open(download_to_file, FileAccess::WRITE); if (!file) { - call_deferred("_request_done", RESULT_DOWNLOAD_FILE_CANT_OPEN, response_code, response_headers, PackedByteArray()); return true; } @@ -370,7 +352,6 @@ bool HTTPRequest::_update_connection() { } if (body_len >= 0) { - if (downloaded == body_len) { call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, body); return true; @@ -397,20 +378,16 @@ bool HTTPRequest::_update_connection() { } void HTTPRequest::_request_done(int p_status, int p_code, const PackedStringArray &headers, const PackedByteArray &p_data) { - cancel_request(); emit_signal("request_completed", p_status, p_code, headers, p_data); } void HTTPRequest::_notification(int p_what) { - if (p_what == NOTIFICATION_INTERNAL_PROCESS) { - if (use_threads) return; bool done = _update_connection(); if (done) { - set_process_internal(false); // cancel_request(); called from _request done now } @@ -424,42 +401,35 @@ void HTTPRequest::_notification(int p_what) { } void HTTPRequest::set_use_threads(bool p_use) { - ERR_FAIL_COND(get_http_client_status() != HTTPClient::STATUS_DISCONNECTED); use_threads = p_use; } bool HTTPRequest::is_using_threads() const { - return use_threads; } void HTTPRequest::set_body_size_limit(int p_bytes) { - ERR_FAIL_COND(get_http_client_status() != HTTPClient::STATUS_DISCONNECTED); body_size_limit = p_bytes; } int HTTPRequest::get_body_size_limit() const { - return body_size_limit; } void HTTPRequest::set_download_file(const String &p_file) { - ERR_FAIL_COND(get_http_client_status() != HTTPClient::STATUS_DISCONNECTED); download_to_file = p_file; } String HTTPRequest::get_download_file() const { - return download_to_file; } void HTTPRequest::set_download_chunk_size(int p_chunk_size) { - ERR_FAIL_COND(get_http_client_status() != HTTPClient::STATUS_DISCONNECTED); client->set_read_chunk_size(p_chunk_size); @@ -474,17 +444,14 @@ HTTPClient::Status HTTPRequest::get_http_client_status() const { } void HTTPRequest::set_max_redirects(int p_max) { - max_redirects = p_max; } int HTTPRequest::get_max_redirects() const { - return max_redirects; } int HTTPRequest::get_downloaded_bytes() const { - return downloaded; } int HTTPRequest::get_body_size() const { @@ -492,24 +459,20 @@ int HTTPRequest::get_body_size() const { } void HTTPRequest::set_timeout(int p_timeout) { - ERR_FAIL_COND(p_timeout < 0); timeout = p_timeout; } int HTTPRequest::get_timeout() { - return timeout; } void HTTPRequest::_timeout() { - cancel_request(); call_deferred("_request_done", RESULT_TIMEOUT, 0, PackedStringArray(), PackedByteArray()); } void HTTPRequest::_bind_methods() { - ClassDB::bind_method(D_METHOD("request", "url", "custom_headers", "ssl_validate_domain", "method", "request_data"), &HTTPRequest::request, DEFVAL(PackedStringArray()), DEFVAL(true), DEFVAL(HTTPClient::METHOD_GET), DEFVAL(String())); ClassDB::bind_method(D_METHOD("cancel_request"), &HTTPRequest::cancel_request); @@ -565,7 +528,6 @@ void HTTPRequest::_bind_methods() { } HTTPRequest::HTTPRequest() { - thread = nullptr; port = 80; |