Improve HTTPRequest default Content-Type
This commit is contained in:
@@ -96,8 +96,11 @@ class HTML5HTTPRequest {
|
||||
}
|
||||
|
||||
request.open (Std.string (parent.method), uri, true);
|
||||
|
||||
if (parent.timeout > 0) {
|
||||
|
||||
request.timeout = parent.timeout;
|
||||
|
||||
}
|
||||
|
||||
if (binary) {
|
||||
@@ -106,18 +109,45 @@ class HTML5HTTPRequest {
|
||||
|
||||
}
|
||||
|
||||
var hasContentType = false;
|
||||
var contentType = null;
|
||||
|
||||
for (header in parent.headers) {
|
||||
|
||||
if (header.name == "Content-Type") hasContentType = true;
|
||||
request.setRequestHeader (header.name, header.value);
|
||||
if (header.name == "Content-Type") {
|
||||
|
||||
contentType = header.value;
|
||||
|
||||
} else {
|
||||
|
||||
request.setRequestHeader (header.name, header.value);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!hasContentType && parent.contentType != null) {
|
||||
if (parent.contentType != null) {
|
||||
|
||||
request.setRequestHeader ("Content-Type", parent.contentType);
|
||||
contentType = parent.contentType;
|
||||
|
||||
}
|
||||
|
||||
if (contentType == null) {
|
||||
|
||||
if (parent.data != null) {
|
||||
|
||||
contentType = "application/octet-stream";
|
||||
|
||||
} else if (query != "") {
|
||||
|
||||
contentType = "application/x-www-form-urlencoded";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (contentType != null) {
|
||||
|
||||
request.setRequestHeader ("Content-Type", contentType);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -261,18 +261,45 @@ class NativeHTTPRequest {
|
||||
var headers = [];
|
||||
headers.push ("Expect: ");
|
||||
|
||||
var hasContentType = false;
|
||||
var contentType = null;
|
||||
|
||||
for (header in cast (parent.headers, Array<Dynamic>)) {
|
||||
|
||||
if (header.name == "Content-Type") hasContentType = true;
|
||||
headers.push ('${header.name}: ${header.value}');
|
||||
if (header.name == "Content-Type") {
|
||||
|
||||
contentType = header.value;
|
||||
|
||||
} else {
|
||||
|
||||
headers.push ('${header.name}: ${header.value}');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!hasContentType) {
|
||||
if (parent.contentType != null) {
|
||||
|
||||
headers.push ("Content-Type: " + parent.contentType);
|
||||
contentType = parent.contentType;
|
||||
|
||||
}
|
||||
|
||||
if (contentType == null) {
|
||||
|
||||
if (parent.data != null) {
|
||||
|
||||
contentType = "application/octet-stream";
|
||||
|
||||
} else if (query != "") {
|
||||
|
||||
contentType = "application/x-www-form-urlencoded";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (contentType != null) {
|
||||
|
||||
headers.push ("Content-Type: " + contentType);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user