|
|
|
@ -182,6 +182,26 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function normalizeHeaders(rawHeaders, contentType) {
|
|
|
|
|
var headers = [];
|
|
|
|
|
|
|
|
|
|
if (rawHeaders) {
|
|
|
|
|
if (rawHeaders instanceof Array) {
|
|
|
|
|
headers = rawHeaders;
|
|
|
|
|
} else {
|
|
|
|
|
for (var headerName in rawHeaders) {
|
|
|
|
|
if (rawHeaders.hasOwnProperty(headerName)) {
|
|
|
|
|
headers.push({ name: headerName, value: rawHeaders[headerName] });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
headers.push({ name: "Content-Type", value: contentType || "application/json" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return headers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var iePropertiesThatCannotBeCopied = ['responseBody', 'responseText', 'responseXML', 'status', 'statusText', 'responseTimeout'];
|
|
|
|
|
extend(FakeXMLHttpRequest.prototype, new window.XMLHttpRequest(), iePropertiesThatCannotBeCopied);
|
|
|
|
|
extend(FakeXMLHttpRequest.prototype, {
|
|
|
|
@ -247,7 +267,19 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getResponseHeader: function(name) {
|
|
|
|
|
return findHeader(name, this.responseHeaders);
|
|
|
|
|
name = name.toLowerCase();
|
|
|
|
|
var resultHeader;
|
|
|
|
|
for(var i = 0; i < this.responseHeaders.length; i++) {
|
|
|
|
|
var header = this.responseHeaders[i];
|
|
|
|
|
if (name === header.name.toLowerCase()) {
|
|
|
|
|
if (resultHeader) {
|
|
|
|
|
resultHeader = [resultHeader, header.value].join(', ');
|
|
|
|
|
} else {
|
|
|
|
|
resultHeader = header.value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return resultHeader;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getAllResponseHeaders: function() {
|
|
|
|
@ -269,30 +301,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
this.statusText = response.statusText || "";
|
|
|
|
|
this.responseText = response.responseText || "";
|
|
|
|
|
this.readyState = 4;
|
|
|
|
|
this.responseHeaders = [];
|
|
|
|
|
|
|
|
|
|
var i;
|
|
|
|
|
if (response.responseHeaders) {
|
|
|
|
|
if (response.responseHeaders instanceof Array) {
|
|
|
|
|
this.responseHeaders = response.responseHeaders;
|
|
|
|
|
} else {
|
|
|
|
|
for (i in response.responseHeaders) {
|
|
|
|
|
if (response.responseHeaders.hasOwnProperty(i)) {
|
|
|
|
|
this.responseHeaders.push({ name: i, value: response.responseHeaders[i] });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.responseHeaders.push({ name: "Content-Type", value: response.contentType || "application/json" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < this.responseHeaders.length; i++) {
|
|
|
|
|
if (typeof(this.responseHeaders[this.responseHeaders[i].name]) === 'undefined') {
|
|
|
|
|
this.responseHeaders[this.responseHeaders[i].name] = this.responseHeaders[i].value;
|
|
|
|
|
} else {
|
|
|
|
|
this.responseHeaders[this.responseHeaders[i].name] += ', ' + this.responseHeaders[i].value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.responseHeaders = normalizeHeaders(response.responseHeaders, response.contentType);
|
|
|
|
|
|
|
|
|
|
this.onload();
|
|
|
|
|
this.onreadystatechange();
|
|
|
|
|