Merge branch 'resident-uhlig-master'
This commit is contained in:
commit
2790018e76
@ -252,10 +252,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
|
|
||||||
getAllResponseHeaders: function() {
|
getAllResponseHeaders: function() {
|
||||||
var responseHeaders = [];
|
var responseHeaders = [];
|
||||||
for (var i in this.responseHeaders) {
|
for (var i = 0; i < this.responseHeaders.length; i++) {
|
||||||
if (this.responseHeaders.hasOwnProperty(i)) {
|
responseHeaders.push(this.responseHeaders[i].name + ': ' +
|
||||||
responseHeaders.push(i + ': ' + this.responseHeaders[i]);
|
this.responseHeaders[i].value);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return responseHeaders.join('\r\n');
|
return responseHeaders.join('\r\n');
|
||||||
},
|
},
|
||||||
@ -270,8 +269,30 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
this.statusText = response.statusText || "";
|
this.statusText = response.statusText || "";
|
||||||
this.responseText = response.responseText || "";
|
this.responseText = response.responseText || "";
|
||||||
this.readyState = 4;
|
this.readyState = 4;
|
||||||
this.responseHeaders = response.responseHeaders ||
|
this.responseHeaders = [];
|
||||||
{"Content-Type": response.contentType || "application/json" };
|
|
||||||
|
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.onload();
|
this.onload();
|
||||||
this.onreadystatechange();
|
this.onreadystatechange();
|
||||||
|
@ -254,6 +254,66 @@ describe("Jasmine Mock Ajax (for toplevel)", function() {
|
|||||||
sharedAjaxResponseBehaviorForZepto_Success(sharedContext);
|
sharedAjaxResponseBehaviorForZepto_Success(sharedContext);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("response with unique header names using an object", function () {
|
||||||
|
beforeEach(function () {
|
||||||
|
client = new fakeGlobal.XMLHttpRequest();
|
||||||
|
client.onreadystatechange = onreadystatechange;
|
||||||
|
client.open("GET", "example.com");
|
||||||
|
client.send();
|
||||||
|
|
||||||
|
request = mockAjax.requests.mostRecent();
|
||||||
|
var responseObject = {status: 200, statusText: "OK", responseText: '["foo"]', responseHeaders: {
|
||||||
|
'X-Header1': 'header 1 value',
|
||||||
|
'X-Header2': 'header 2 value',
|
||||||
|
'X-Header3': 'header 3 value'
|
||||||
|
}};
|
||||||
|
request.response(responseObject);
|
||||||
|
response = success.calls.mostRecent().args[2];
|
||||||
|
});
|
||||||
|
|
||||||
|
it("getResponseHeader should return the each value", function () {
|
||||||
|
expect(response.getResponseHeader('X-Header1')).toBe('header 1 value');
|
||||||
|
expect(response.getResponseHeader('X-Header2')).toBe('header 2 value');
|
||||||
|
expect(response.getResponseHeader('X-Header3')).toBe('header 3 value');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("getAllResponseHeaders should return all values", function () {
|
||||||
|
expect(response.getAllResponseHeaders()).toBe([
|
||||||
|
"X-Header1: header 1 value",
|
||||||
|
"X-Header2: header 2 value",
|
||||||
|
"X-Header3: header 3 value"
|
||||||
|
].join("\r\n"));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("response with multiple headers of the same name using an array of objects", function () {
|
||||||
|
beforeEach(function () {
|
||||||
|
client = new fakeGlobal.XMLHttpRequest();
|
||||||
|
client.onreadystatechange = onreadystatechange;
|
||||||
|
client.open("GET", "example.com");
|
||||||
|
client.send();
|
||||||
|
|
||||||
|
request = mockAjax.requests.mostRecent();
|
||||||
|
var responseObject = {status: 200, statusText: "OK", responseText: '["foo"]', responseHeaders: [
|
||||||
|
{ name: 'X-Header', value: 'header value 1' },
|
||||||
|
{ name: 'X-Header', value: 'header value 2' }
|
||||||
|
]};
|
||||||
|
request.response(responseObject);
|
||||||
|
response = success.calls.mostRecent().args[2];
|
||||||
|
});
|
||||||
|
|
||||||
|
it("getResponseHeader should return all values comma separated", function () {
|
||||||
|
expect(response.getResponseHeader('X-Header')).toBe('header value 1, header value 2');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("getAllResponseHeaders should return all values", function () {
|
||||||
|
expect(response.getAllResponseHeaders()).toBe([
|
||||||
|
"X-Header: header value 1",
|
||||||
|
"X-Header: header value 2"
|
||||||
|
].join("\r\n"));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("the content type defaults to application/json", function () {
|
describe("the content type defaults to application/json", function () {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
client = new fakeGlobal.XMLHttpRequest();
|
client = new fakeGlobal.XMLHttpRequest();
|
||||||
|
Loading…
Reference in New Issue
Block a user