Merge pull request #1535 from player-03/buildBuffer

Only call `buildBuffer()` when needed.
This commit is contained in:
player-03
2022-06-04 01:23:52 -04:00
committed by GitHub
2 changed files with 4 additions and 8 deletions

View File

@@ -42,7 +42,7 @@ class NativeHTTPRequest
private static var multiAddHandle:Deque<CURL>; private static var multiAddHandle:Deque<CURL>;
#end #end
private static var cookieList:Array<String>; private static var cookieList:Array<String>;
private var buffer:BytesBuffer = new BytesBuffer(); private var buffer:BytesBuffer = new BytesBuffer();
private var bytes:Bytes; private var bytes:Bytes;
private var bytesLoaded:Int; private var bytesLoaded:Int;
@@ -362,12 +362,12 @@ class NativeHTTPRequest
return promise.future; return promise.future;
} }
private function buildBuffer() { private function buildBuffer() {
bytes = buffer.getBytes(); bytes = buffer.getBytes();
return bytes; return bytes;
} }
// Event Handlers // Event Handlers
private function curl_onHeader(curl:CURL, header:String):Void private function curl_onHeader(curl:CURL, header:String):Void
{ {
@@ -571,7 +571,7 @@ class NativeHTTPRequest
{ {
if (!instance.promise.isError) if (!instance.promise.isError)
{ {
instance.promise.complete(instance.bytes); instance.promise.complete(instance.buildBuffer());
} }
} }
else if (instance.bytes != null) else if (instance.bytes != null)

View File

@@ -110,10 +110,6 @@ public function load(uri:String = null):Future<T>
future.onComplete(function(bytes) future.onComplete(function(bytes)
{ {
#if sys
bytes = @:privateAccess __backend.buildBuffer();
#end
responseData = fromBytes(bytes); responseData = fromBytes(bytes);
promise.complete(responseData); promise.complete(responseData);
}); });