mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
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:

committed by
Hristo Hristov

parent
81288df17f
commit
6282baefd8
@ -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");
|
||||
};
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user