Ignore the case when getting a response header (#2250)

According to the RFC: https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
"Field names are case-insensitive".
For instance, Google Cloud Endpoints use "content-type" in the response.
This commit is contained in:
Elie Mélois
2016-06-20 12:42:50 +02:00
committed by Hristo Hristov
parent 81288df17f
commit 6282baefd8
2 changed files with 25 additions and 3 deletions

View File

@ -345,3 +345,21 @@ export function test_responseType(done) {
);
done(null);
}
export function test_getResponseHeader() {
const xhr = <any>new XMLHttpRequest();
const response = {
statusCode: 200,
content: {
toString: function() { return this.raw },
raw: '{"data": 42}'
},
headers: {
"content-type": "application/json"
}
}
xhr._loadResponse(response);
TKUnit.assertEqual(xhr.getResponseHeader("Content-Type"), "application/json");
};

View File

@ -194,10 +194,14 @@ export class XMLHttpRequest {
public getResponseHeader(header: string): string {
if (types.isString(header) && this._readyState > 1
&& this._headers
&& this._headers[header]
&& !this._errorFlag
) {
return this._headers[header];
header = header.toLowerCase();
for (var i in this._headers) {
if (i.toLowerCase() === header) {
return this._headers[i];
}
}
}
return null;