diff --git a/lime/_backend/native/NativeHTTPRequest.hx b/lime/_backend/native/NativeHTTPRequest.hx index 71ae68853..fc5ccf847 100644 --- a/lime/_backend/native/NativeHTTPRequest.hx +++ b/lime/_backend/native/NativeHTTPRequest.hx @@ -33,6 +33,7 @@ class NativeHTTPRequest { private var curl:CURL; private var parent:_IHTTPRequest; private var promise:Promise; + private var readPosition:Int; public function new () { @@ -172,6 +173,7 @@ class NativeHTTPRequest { bytesLoaded = 0; bytesTotal = 0; + readPosition = 0; if (curl == 0) { @@ -348,7 +350,29 @@ class NativeHTTPRequest { private function curl_onRead (max:Int, input:Bytes):Bytes { - return input; + if (readPosition == 0 && max >= input.length) { + + return input; + + } else if (readPosition >= input.length) { + + return Bytes.alloc (0); + + } else { + + var length = max; + + if (readPosition + length > input.length) { + + length = input.length - readPosition; + + } + + var data = input.sub (readPosition, length); + readPosition += length; + return data; + + } }