Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Lowercase header names in parseResponseHeaders #5489

Merged
merged 1 commit into from
Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions addon/-private/utils/parse-response-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export default function parseResponseHeaders(headersString) {
let value = header.substring(j + 1, header.length).trim();

if (value) {
let lowerCasedField = field.toLowerCase();

headers[lowerCasedField] = value;
headers[field] = value;
}
}
Expand Down
2 changes: 1 addition & 1 deletion addon/adapters/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ const RESTAdapter = Adapter.extend(BuildURLMixin, {
*/
generatedDetailedMessage: function(status, headers, payload, requestData) {
let shortenedPayload;
let payloadContentType = headers['Content-Type'] || 'Empty Content-Type';
let payloadContentType = headers['content-type'] || 'Empty Content-Type';

if (payloadContentType === 'text/html' && payload.length > 250) {
shortenedPayload = '[Omitted Lengthy HTML]';
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/adapters/rest-adapter/detailed-message-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test('generating a wonderfully friendly error message should work', function(ass

let friendlyMessage = adapter.generatedDetailedMessage(
418,
{ 'Content-Type': 'text/plain' },
{ 'content-type': 'text/plain' },
"I'm a little teapot, short and stout",
{
url: '/teapots/testing',
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/utils/parse-response-headers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test('header parsing', function(assert) {

let headers = parseResponseHeaders(headersString);

assert.equal(headers['Content-Encoding'], 'gzip', 'parses basic header pair');
assert.equal(headers['content-encoding'], 'gzip', 'parses basic header pair');
assert.equal(
headers['content-type'],
'application/json; charset=utf-8',
Expand All @@ -34,6 +34,7 @@ test('field-name parsing', function(assert) {
let headersString = [
' name-with-leading-whitespace: some value',
'name-with-whitespace-before-colon : another value',
'Uppercase-Name: yet another value',
].join(CRLF);

let headers = parseResponseHeaders(headersString);
Expand All @@ -48,6 +49,7 @@ test('field-name parsing', function(assert) {
'another value',
'strips whitespace before colon from field-name'
);
assert.equal(headers['uppercase-name'], 'yet another value', 'lowercases the field-name');
});

test('field-value parsing', function(assert) {
Expand Down Expand Up @@ -92,9 +94,9 @@ test('ignores headers that do not contain a colon', function(assert) {

let headers = parseResponseHeaders(headersString);

assert.deepEqual(headers['Content-Encoding'], 'gzip', 'parses basic header pair');
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');
assert.equal(Object.keys(headers).length, 3, 'only has the three valid headers');
});

test('tollerate extra new-lines', function(assert) {
Expand Down