From 5b96b33774cbfa8918303544b7c04693f99452d3 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 24 May 2017 17:18:52 -0700 Subject: [PATCH] Fix native HTTPRequest larger uploads --- lime/_backend/native/NativeHTTPRequest.hx | 26 ++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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; + + } }