Skip to content

Commit

Permalink
Merge pull request #5029 from emberjs/header-parsing
Browse files Browse the repository at this point in the history
loosen header parsing slightly
  • Loading branch information
stefanpenner authored Jun 22, 2017
2 parents ac01921 + b1bacb8 commit ced0cdf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion addon/-private/utils/parse-response-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function parseResponseHeaders(headersString) {
}

if (foundSep === false) {
break;
continue;
}

let field = header.substring(0, j).trim();
Expand Down
13 changes: 12 additions & 1 deletion tests/unit/utils/parse-response-headers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,26 @@ test('field-value parsing', function(assert) {
assert.equal(headers['value-with-colon'], 'value with: a colon', 'has correct value when value contains a colon');
assert.equal(headers['value-with-trailing-whitespace'], 'banana', 'strips trailing whitespace from field-value');
});
"\r\nfoo: bar"

test('ignores headers that do not contain a colon', function(assert) {
let headersString = [
'Content-Encoding: gzip',
'I am ignored because I do not contain a colon'
'I am ignored because I do not contain a colon',
'apple: pie'
].join(CRLF);

let headers = parseResponseHeaders(headersString);

assert.deepEqual(headers['Content-Encoding'], 'gzip', 'parses basic header pair');
assert.deepEqual(headers['apple'], 'pie', 'parses basic header pair');
assert.equal(Object.keys(headers).length, 2, 'only has the one valid header');
});

test('tollerate extra new-lines', function(assert) {
let headersString = CRLF + 'foo: bar';
let headers = parseResponseHeaders(headersString);

assert.deepEqual(headers['foo'], 'bar', 'parses basic header pair');
assert.equal(Object.keys(headers).length, 1, 'only has the one valid header');
});

0 comments on commit ced0cdf

Please sign in to comment.