diff --git a/core/modules/utils/dom/http.js b/core/modules/utils/dom/http.js index 952704138..6e07b1040 100644 --- a/core/modules/utils/dom/http.js +++ b/core/modules/utils/dom/http.js @@ -34,6 +34,23 @@ exports.httpRequest = function(options) { }); return result; }, + getHeader = function(targetHeader) { + return headers[targetHeader] || headers[targetHeader.toLowerCase()]; + }, + isSimpleRequest = function(type,headers) { + if(["GET","HEAD","POST"].indexOf(type) === -1) { + return false; + } + for(var header in headers) { + if(["accept","accept-language","content-language","content-type"].indexOf(header.toLowerCase()) === -1) { + return false; + } + } + if(hasHeader("Content-Type") && ["application/x-www-form-urlencoded","multipart/form-data","text/plain"].indexOf(getHeader["Content-Type"]) === -1) { + return false; + } + return true; + }, returnProp = options.returnProp || "responseText", request = new XMLHttpRequest(), data = "", @@ -76,7 +93,7 @@ exports.httpRequest = function(options) { if(data && !hasHeader("Content-Type")) { request.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); } - if(!hasHeader("X-Requested-With")) { + if(!hasHeader("X-Requested-With") && !isSimpleRequest(type,headers)) { request.setRequestHeader("X-Requested-With","TiddlyWiki"); } try { diff --git a/plugins/tiddlywiki/tiddlyweb/tiddlywebadaptor.js b/plugins/tiddlywiki/tiddlyweb/tiddlywebadaptor.js index 683c305c8..b31610deb 100644 --- a/plugins/tiddlywiki/tiddlyweb/tiddlywebadaptor.js +++ b/plugins/tiddlywiki/tiddlyweb/tiddlywebadaptor.js @@ -114,6 +114,10 @@ TiddlyWebAdaptor.prototype.login = function(username,password,callback) { }, callback: function(err) { callback(err); + }, + headers: { + "accept": "application/json", + "X-Requested-With": "TiddlyWiki" } }; this.logger.log("Logging in:",options); @@ -132,6 +136,10 @@ TiddlyWebAdaptor.prototype.logout = function(callback) { }, callback: function(err,data) { callback(err); + }, + headers: { + "accept": "application/json", + "X-Requested-With": "TiddlyWiki" } }; this.logger.log("Logging out:",options);