Improve HTTPRequest default Content-Type
This commit is contained in:
@@ -96,8 +96,11 @@ class HTML5HTTPRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
request.open (Std.string (parent.method), uri, true);
|
request.open (Std.string (parent.method), uri, true);
|
||||||
|
|
||||||
if (parent.timeout > 0) {
|
if (parent.timeout > 0) {
|
||||||
|
|
||||||
request.timeout = parent.timeout;
|
request.timeout = parent.timeout;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (binary) {
|
if (binary) {
|
||||||
@@ -106,18 +109,45 @@ class HTML5HTTPRequest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var hasContentType = false;
|
var contentType = null;
|
||||||
|
|
||||||
for (header in parent.headers) {
|
for (header in parent.headers) {
|
||||||
|
|
||||||
if (header.name == "Content-Type") hasContentType = true;
|
if (header.name == "Content-Type") {
|
||||||
|
|
||||||
|
contentType = header.value;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
request.setRequestHeader (header.name, header.value);
|
request.setRequestHeader (header.name, header.value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasContentType && parent.contentType != null) {
|
}
|
||||||
|
|
||||||
request.setRequestHeader ("Content-Type", parent.contentType);
|
if (parent.contentType != null) {
|
||||||
|
|
||||||
|
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 = [];
|
var headers = [];
|
||||||
headers.push ("Expect: ");
|
headers.push ("Expect: ");
|
||||||
|
|
||||||
var hasContentType = false;
|
var contentType = null;
|
||||||
|
|
||||||
for (header in cast (parent.headers, Array<Dynamic>)) {
|
for (header in cast (parent.headers, Array<Dynamic>)) {
|
||||||
|
|
||||||
if (header.name == "Content-Type") hasContentType = true;
|
if (header.name == "Content-Type") {
|
||||||
|
|
||||||
|
contentType = header.value;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
headers.push ('${header.name}: ${header.value}');
|
headers.push ('${header.name}: ${header.value}');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasContentType) {
|
}
|
||||||
|
|
||||||
headers.push ("Content-Type: " + parent.contentType);
|
if (parent.contentType != null) {
|
||||||
|
|
||||||
|
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