From cfb93c7d74bffd9e2c408328ad225ded1de47c19 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 18 Oct 2017 12:44:22 -0700 Subject: [PATCH] Restore previous response header default, minor cleanup --- lime/_backend/native/NativeHTTPRequest.hx | 44 +++++++++++++---------- lime/net/HTTPRequest.hx | 2 +- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/lime/_backend/native/NativeHTTPRequest.hx b/lime/_backend/native/NativeHTTPRequest.hx index 89ff89016..2065239a2 100644 --- a/lime/_backend/native/NativeHTTPRequest.hx +++ b/lime/_backend/native/NativeHTTPRequest.hx @@ -173,13 +173,12 @@ class NativeHTTPRequest { } + } else { + + data = Bytes.alloc (0); + } - - else { - - data = Bytes.alloc(0); - - } + } curl.setOption (URL, uri); @@ -269,12 +268,13 @@ class NativeHTTPRequest { curl.setOption (WRITEFUNCTION, curl_onWrite); if (parent.enableResponseHeaders) { - + parent.responseHeaders = []; - curl.setOption (HEADERFUNCTION, curl_onHeader); } + curl.setOption (HEADERFUNCTION, curl_onHeader); + // TODO: Add support for cookies: https://curl.haxx.se/docs/http-cookies.html if (parent.withCredentials) { @@ -304,9 +304,13 @@ class NativeHTTPRequest { threadPool.sendComplete ({ instance: this, promise: promise, result: bytes }); + } else if (bytes != null) { + + threadPool.sendError ({ instance: this, promise: promise, error: bytes.getString (0, bytes.length) }); + } else { - - threadPool.sendError ({ instance: this, promise: promise, error: bytes == null ? 'Status ${parent.responseStatus}' : Std.string(bytes)}); + + threadPool.sendError ({ instance: this, promise: promise, error: 'Status ${parent.responseStatus}' }); } @@ -399,21 +403,25 @@ class NativeHTTPRequest { private function curl_onHeader (output:Bytes, size:Int, nmemb:Int):Int { - + var parts = Std.string (output).split (': '); - + if (parts.length == 2) { - - parent.responseHeaders.push (new HTTPRequestHeader (parts[0], parts[1])); - + + if (parent.enableResponseHeaders) { + + parent.responseHeaders.push (new HTTPRequestHeader (parts[0], parts[1])); + + } + switch (parts[0]) { - + case 'Content-Length': growBuffer (Std.parseInt (parts[1])); - + } - + } return size * nmemb; diff --git a/lime/net/HTTPRequest.hx b/lime/net/HTTPRequest.hx index feeaba55a..dd5b58a6e 100644 --- a/lime/net/HTTPRequest.hx +++ b/lime/net/HTTPRequest.hx @@ -53,7 +53,7 @@ private class AbstractHTTPRequest implements _IHTTPRequest { contentType = "application/x-www-form-urlencoded"; followRedirects = true; - enableResponseHeaders = true; + enableResponseHeaders = false; formData = new Map (); headers = []; method = GET;