mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +00:00
Fix httpRequest() header handling
Header names are not case sensitive, so the old code failed if it was called with a "Content-Type" header
This commit is contained in:
parent
c23eedd069
commit
a2796d89ab
@ -24,6 +24,16 @@ exports.httpRequest = function(options) {
|
|||||||
var type = options.type || "GET",
|
var type = options.type || "GET",
|
||||||
url = options.url,
|
url = options.url,
|
||||||
headers = options.headers || {accept: "application/json"},
|
headers = options.headers || {accept: "application/json"},
|
||||||
|
hasHeader = function(targetHeader) {
|
||||||
|
targetHeader = targetHeader.toLowerCase();
|
||||||
|
var result = false;
|
||||||
|
$tw.utils.each(headers,function(header,headerTitle,object) {
|
||||||
|
if(headerTitle.toLowerCase() === targetHeader) {
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
},
|
||||||
returnProp = options.returnProp || "responseText",
|
returnProp = options.returnProp || "responseText",
|
||||||
request = new XMLHttpRequest(),
|
request = new XMLHttpRequest(),
|
||||||
data = "",
|
data = "",
|
||||||
@ -63,10 +73,10 @@ exports.httpRequest = function(options) {
|
|||||||
request.setRequestHeader(headerTitle,header);
|
request.setRequestHeader(headerTitle,header);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if(data && !$tw.utils.hop(headers,"Content-type")) {
|
if(data && !hasHeader("Content-Type")) {
|
||||||
request.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8");
|
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
|
||||||
}
|
}
|
||||||
if(!$tw.utils.hop(headers,"X-Requested-With")) {
|
if(!hasHeader("X-Requested-With")) {
|
||||||
request.setRequestHeader("X-Requested-With","TiddlyWiki");
|
request.setRequestHeader("X-Requested-With","TiddlyWiki");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user