Fix HTML5 HTTPClient failure detection

(cherry picked from commit 9ea4452d21)
This commit is contained in:
Leon Krause 2018-02-16 05:11:25 +01:00 committed by Hein-Pieter van Braam
parent 2abbdcaa20
commit 2714b851bf
1 changed files with 7 additions and 11 deletions

View File

@ -239,15 +239,11 @@ Error HTTPClient::poll() {
case STATUS_REQUESTING: case STATUS_REQUESTING:
polled_response_code = godot_xhr_get_status(xhr_id); polled_response_code = godot_xhr_get_status(xhr_id);
int response_length = godot_xhr_get_response_length(xhr_id); if (godot_xhr_get_ready_state(xhr_id) != XHR_READY_STATE_DONE) {
if (response_length == 0) { return OK;
godot_xhr_ready_state_t ready_state = godot_xhr_get_ready_state(xhr_id); } else if (!polled_response_code) {
if (ready_state == XHR_READY_STATE_HEADERS_RECEIVED || ready_state == XHR_READY_STATE_LOADING) { status = STATUS_CONNECTION_ERROR;
return OK; return ERR_CONNECTION_ERROR;
} else {
status = STATUS_CONNECTION_ERROR;
return ERR_CONNECTION_ERROR;
}
} }
status = STATUS_BODY; status = STATUS_BODY;
@ -263,9 +259,9 @@ Error HTTPClient::poll() {
polled_response_header = String::utf8(reinterpret_cast<const char *>(read.ptr())); polled_response_header = String::utf8(reinterpret_cast<const char *>(read.ptr()));
read = PoolByteArray::Read(); read = PoolByteArray::Read();
polled_response.resize(response_length); polled_response.resize(godot_xhr_get_response_length(xhr_id));
write = polled_response.write(); write = polled_response.write();
godot_xhr_get_response(xhr_id, write.ptr(), response_length); godot_xhr_get_response(xhr_id, write.ptr(), polled_response.size());
write = PoolByteArray::Write(); write = PoolByteArray::Write();
break; break;
} }