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

@@ -119,7 +119,7 @@ export class XMLHttpRequest {
this._responseTextReader = () => r.content.toString();
this._response = JSON.parse(this.responseText);
// Add toString() method to ease debugging and
// Add toString() method to ease debugging and
// make Angular2 response.text() method work properly.
Object.defineProperty(this._response, "toString", {
configurable: true,
@@ -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;