From 8a74a9f7c333866842f30e25653faf9ef3373ebc Mon Sep 17 00:00:00 2001 From: Ryan Pastorelle Date: Tue, 5 May 2015 14:14:48 -0700 Subject: [PATCH] Force `responseHeaders` to lower case to respect case-insensitivity Summary: `XMLHttpRequest.getResponseHeader` is case-insensitive, therefor the React-Native implementation needs to mimic this behavior as to not break libraries that are dependent on this. There is a corresponding issue in `superagent` but this is the root cause (https://github.com/visionmedia/superagent/issues/636). Closes https://github.com/facebook/react-native/pull/1138 Github Author: Ryan Pastorelle Test Plan: Imported from GitHub, without a `Test Plan:` line. --- Libraries/Network/XMLHttpRequestBase.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Libraries/Network/XMLHttpRequestBase.js b/Libraries/Network/XMLHttpRequestBase.js index 4a4f16ac685178..99a327b5f236eb 100644 --- a/Libraries/Network/XMLHttpRequestBase.js +++ b/Libraries/Network/XMLHttpRequestBase.js @@ -66,7 +66,7 @@ class XMLHttpRequestBase { getResponseHeader(header: string): ?string { if (this.responseHeaders) { - var value = this.responseHeaders[header]; + var value = this.responseHeaders[header.toLowerCase()]; return value !== undefined ? value : null; } return null; @@ -132,7 +132,12 @@ class XMLHttpRequestBase { return; } this.status = status; - this.responseHeaders = responseHeaders || {}; + // Headers should be case-insensitive + var lcResponseHeaders = {}; + for (var header in responseHeaders) { + lcResponseHeaders[header.toLowerCase()] = responseHeaders[header]; + } + this.responseHeaders = lcResponseHeaders; this.responseText = responseText; this._setReadyState(this.DONE); this._sendLoad();