Find response case-insensitively
This commit is contained in:
parent
0b2b4a4a2e
commit
864c8df82b
@ -172,6 +172,15 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
this.requestHeaders = {};
|
||||
}
|
||||
|
||||
function findHeader(name, headers) {
|
||||
name = name.toLowerCase();
|
||||
for (var header in headers) {
|
||||
if (header.toLowerCase() === name) {
|
||||
return headers[header];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var iePropertiesThatCannotBeCopied = ['responseBody', 'responseText', 'responseXML', 'status', 'statusText', 'responseTimeout'];
|
||||
extend(FakeXMLHttpRequest.prototype, new window.XMLHttpRequest(), iePropertiesThatCannotBeCopied);
|
||||
extend(FakeXMLHttpRequest.prototype, {
|
||||
@ -221,11 +230,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
},
|
||||
|
||||
contentType: function() {
|
||||
for (var header in this.requestHeaders) {
|
||||
if (header.toLowerCase() === 'content-type') {
|
||||
return this.requestHeaders[header];
|
||||
}
|
||||
}
|
||||
return findHeader('content-type', this.requestHeaders);
|
||||
},
|
||||
|
||||
data: function() {
|
||||
@ -237,7 +242,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
},
|
||||
|
||||
getResponseHeader: function(name) {
|
||||
return this.responseHeaders[name];
|
||||
return findHeader(name, this.responseHeaders);
|
||||
},
|
||||
|
||||
getAllResponseHeaders: function() {
|
||||
|
@ -219,12 +219,26 @@ describe("FakeXMLHttpRequest", function() {
|
||||
expect(xhr.contentType()).toEqual('something');
|
||||
});
|
||||
|
||||
it("gets the content-type even when the casing is not to spec", function() {
|
||||
it("gets the content-type case-insensitively", function() {
|
||||
xhr.setRequestHeader('content-Type', 'some other thing');
|
||||
expect(xhr.contentType()).toEqual('some other thing');
|
||||
});
|
||||
});
|
||||
|
||||
describe("getResponseHeader", function() {
|
||||
it("gets a response header case-insensitively", function() {
|
||||
xhr.send();
|
||||
xhr.response({
|
||||
status: 200,
|
||||
responseHeaders: {
|
||||
'X-Foo': 'Bar'
|
||||
}
|
||||
});
|
||||
|
||||
expect(xhr.getResponseHeader('x-foo')).toBe('Bar');
|
||||
});
|
||||
});
|
||||
|
||||
describe("when a fake XMLHttpRequest is created", function() {
|
||||
it("inherits the properties of the real XMLHttpRequest object", function() {
|
||||
expect(xhr.someOtherProperty).toBe('someValue');
|
||||
|
Loading…
Reference in New Issue
Block a user