소스 검색

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.

Drachenfels 11 년 전
부모
커밋
b86d1e39b9
1개의 변경된 파일16개의 추가작업 그리고 12개의 파일을 삭제
  1. 16 12
      core/io/http_client.cpp

+ 16 - 12
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;
 
 	}