Permalink
Browse files

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 #10034

Differential Revision: D3917020

fbshipit-source-id: f4e920f6bebacc3aa5c52c84348157d2b530480f
  • Loading branch information...
1 parent 1142d9d commit 24c72f513e48f0bdc40820b43262328fe2c301d4 @arv arv committed with Facebook Github Bot 1 Sep 23, 2016
Showing with 14 additions and 1 deletion.
  1. +1 −1 Libraries/Network/XMLHttpRequest.js
  2. +13 −0 Libraries/Network/__tests__/XMLHttpRequest-test.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 {
@@ -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');
+ });
+
});

0 comments on commit 24c72f5

Please sign in to comment.