Restore previous response header default, minor cleanup
This commit is contained in:
@@ -173,13 +173,12 @@ class NativeHTTPRequest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
data = Bytes.alloc (0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
|
||||||
|
|
||||||
data = Bytes.alloc(0);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
curl.setOption (URL, uri);
|
curl.setOption (URL, uri);
|
||||||
@@ -269,12 +268,13 @@ class NativeHTTPRequest {
|
|||||||
curl.setOption (WRITEFUNCTION, curl_onWrite);
|
curl.setOption (WRITEFUNCTION, curl_onWrite);
|
||||||
|
|
||||||
if (parent.enableResponseHeaders) {
|
if (parent.enableResponseHeaders) {
|
||||||
|
|
||||||
parent.responseHeaders = [];
|
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
|
// TODO: Add support for cookies: https://curl.haxx.se/docs/http-cookies.html
|
||||||
|
|
||||||
if (parent.withCredentials) {
|
if (parent.withCredentials) {
|
||||||
@@ -304,9 +304,13 @@ class NativeHTTPRequest {
|
|||||||
|
|
||||||
threadPool.sendComplete ({ instance: this, promise: promise, result: bytes });
|
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 {
|
} 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 {
|
private function curl_onHeader (output:Bytes, size:Int, nmemb:Int):Int {
|
||||||
|
|
||||||
var parts = Std.string (output).split (': ');
|
var parts = Std.string (output).split (': ');
|
||||||
|
|
||||||
if (parts.length == 2) {
|
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]) {
|
switch (parts[0]) {
|
||||||
|
|
||||||
case 'Content-Length':
|
case 'Content-Length':
|
||||||
|
|
||||||
growBuffer (Std.parseInt (parts[1]));
|
growBuffer (Std.parseInt (parts[1]));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return size * nmemb;
|
return size * nmemb;
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ private class AbstractHTTPRequest<T> implements _IHTTPRequest {
|
|||||||
|
|
||||||
contentType = "application/x-www-form-urlencoded";
|
contentType = "application/x-www-form-urlencoded";
|
||||||
followRedirects = true;
|
followRedirects = true;
|
||||||
enableResponseHeaders = true;
|
enableResponseHeaders = false;
|
||||||
formData = new Map ();
|
formData = new Map ();
|
||||||
headers = [];
|
headers = [];
|
||||||
method = GET;
|
method = GET;
|
||||||
|
|||||||
Reference in New Issue
Block a user