FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Ignore the case when getting a response header · NativeScript/NativeScript@c997427 · GitHub

Commit c997427

Browse files
committed
Ignore the case when getting a response header
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.
1 parent 8fd0476 commit c997427

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

‎tests/app/xhr-tests.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,21 @@ export function test_responseType(done) {
345345
);
346346
done(null);
347347
}
348+
349+
export function test_getResponseHeader() {
350+
const xhr = <any>new XMLHttpRequest();
351+
const response = {
352+
statusCode: 200,
353+
content: {
354+
toString: function() { return this.raw },
355+
raw: '{"data": 42}'
356+
},
357+
headers: {
358+
"content-type": "application/json"
359+
}
360+
361+
}
362+
xhr._loadResponse(response);
363+
364+
TKUnit.assertEqual(xhr.getResponseHeader("Content-Type"), "application/json");
365+
};

‎tns-core-modules/xhr/xhr.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export class XMLHttpRequest {
119119
this._responseTextReader = () => r.content.toString();
120120
this._response = JSON.parse(this.responseText);
121121

122-
// Add toString() method to ease debugging and
122+
// Add toString() method to ease debugging and
123123
// make Angular2 response.text() method work properly.
124124
Object.defineProperty(this._response, "toString", {
125125
configurable: true,
@@ -194,10 +194,14 @@ export class XMLHttpRequest {
194194
public getResponseHeader(header: string): string {
195195
if (types.isString(header) && this._readyState > 1
196196
&& this._headers
197-
&& this._headers[header]
198197
&& !this._errorFlag
199198
) {
200-
return this._headers[header];
199+
header = header.toLowerCase();
200+
for (var i in this._headers) {
201+
if (i.toLowerCase() === header) {
202+
return this._headers[i];
203+
}
204+
}
201205
}
202206

203207
return null;

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL