diff options
| author | Drachenfels | 2014-08-21 16:08:53 +0100 |
|---|---|---|
| committer | Drachenfels | 2014-08-21 16:13:57 +0100 |
| commit | b86d1e39b9a201c0c6b97c29217ef112c850a6aa (patch) | |
| tree | f42397415905d53b0b6ccecfcd6640e6abc4f4bc /core/io/http_client.cpp | |
| parent | 89fa70706f9166765c3ac3f799225a467800f065 (diff) | |
| download | godot-b86d1e39b9a201c0c6b97c29217ef112c850a6aa.tar.gz godot-b86d1e39b9a201c0c6b97c29217ef112c850a6aa.tar.zst godot-b86d1e39b9a201c0c6b97c29217ef112c850a6aa.zip | |
Fixed copy process of stream of bytes for HttpClient.
=====================================================
Previously if request was not chunked and longer than arbitrary chunk of
4096 bytes, rest was truncated. With this commit, we will copy
everything we have in the memmory.
Diffstat (limited to '')
| -rw-r--r-- | core/io/http_client.cpp | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index 27e202f47..60a200af1 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -500,20 +500,24 @@ ByteArray HTTPClient::read_response_body_chunk() { } } else { - ByteArray::Write r = tmp_read.write(); - int rec=0; - err = connection->get_partial_data(r.ptr(),MIN(body_left,tmp_read.size()),rec); - if (rec>0) { - ByteArray ret; - ret.resize(rec); - ByteArray::Write w = ret.write(); - copymem(w.ptr(),r.ptr(),rec); - body_left-=rec; - if (body_left==0) { - status=STATUS_CONNECTED; + ByteArray ret; + ret.resize(MAX(body_left,tmp_read.size())); + ByteArray::Write w = ret.write(); + int _offset = 0; + while (body_left > 0) { + ByteArray::Write r = tmp_read.write(); + int rec=0; + err = connection->get_partial_data(r.ptr(),MIN(body_left,tmp_read.size()),rec); + if (rec>0) { + copymem(w.ptr()+_offset,r.ptr(),rec); + body_left-=rec; + _offset += rec; } - return ret; } + if (body_left==0) { + status=STATUS_CONNECTED; + } + return ret; } |
