Skip to content

Commit

Permalink
XMLHttpRequest.getAllResponseHeaders should use CRLF
Browse files Browse the repository at this point in the history
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
arv authored and Facebook Github Bot 1 committed Sep 23, 2016
1 parent 1142d9d commit 24c72f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Libraries/Network/XMLHttpRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions Libraries/Network/__tests__/XMLHttpRequest-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.