From 24c72f513e48f0bdc40820b43262328fe2c301d4 Mon Sep 17 00:00:00 2001 From: Erik Arvidsson Date: Fri, 23 Sep 2016 16:23:16 -0700 Subject: [PATCH] XMLHttpRequest.getAllResponseHeaders should use CRLF Summary: XMLHttpRequest.prototype.getAllResponseHeaders was previously joining the headers with `\n`. The spec at: https://xhr.spec.whatwg.org/#the-getallresponseheaders()-method step 3.2, requires the headers to be joined using `\r\n`. Closes https://github.com/facebook/react-native/pull/10034 Differential Revision: D3917020 fbshipit-source-id: f4e920f6bebacc3aa5c52c84348157d2b530480f --- Libraries/Network/XMLHttpRequest.js | 2 +- Libraries/Network/__tests__/XMLHttpRequest-test.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Libraries/Network/XMLHttpRequest.js b/Libraries/Network/XMLHttpRequest.js index 28a228ccd1fe2a..ef93632c732603 100644 --- a/Libraries/Network/XMLHttpRequest.js +++ b/Libraries/Network/XMLHttpRequest.js @@ -340,7 +340,7 @@ class XMLHttpRequest extends EventTarget(...XHR_EVENTS) { var headers = this.responseHeaders || {}; return Object.keys(headers).map((headerName) => { return headerName + ': ' + headers[headerName]; - }).join('\n'); + }).join('\r\n'); } getResponseHeader(header: string): ?string { diff --git a/Libraries/Network/__tests__/XMLHttpRequest-test.js b/Libraries/Network/__tests__/XMLHttpRequest-test.js index 2f343a8fe7eb70..7b3d7a5e0afe88 100644 --- a/Libraries/Network/__tests__/XMLHttpRequest-test.js +++ b/Libraries/Network/__tests__/XMLHttpRequest-test.js @@ -194,4 +194,17 @@ describe('XMLHttpRequest', function() { expect(handleProgress.mock.calls[0][0].total).toBe(100); }); + it('should combine response headers with CRLF', function() { + xhr.open('GET', 'blabla'); + xhr.send(); + xhr.__didReceiveResponse(1, 200, { + 'Content-Type': 'text/plain; charset=utf-8', + 'Content-Length': '32', + }); + + expect(xhr.getAllResponseHeaders()).toBe( + 'Content-Type: text/plain; charset=utf-8\r\n' + + 'Content-Length: 32'); + }); + });