Skip to content
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
12 changes: 11 additions & 1 deletion src/fastboot-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ function FastBootHeaders(headers) {
this.headers = {};

for (var header in headers) {
this.headers[header] = headers[header].split(', ');
let value = headers[header];

// Express gives us either a string
// or an array of strings if there are multiple values.
// We want to support the Header spec
// so we will coerce to an array always.
if (typeof value === 'string') {
value = [value];
}

this.headers[header] = value;
}
}

Expand Down
29 changes: 14 additions & 15 deletions test/fastboot-headers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,28 @@ var alchemistRequire = require('broccoli-module-alchemist/require');
var FastBootHeaders = alchemistRequire('fastboot-headers.js');

describe('FastBootHeaders', function() {
it('returns an array of header values from getAll, regardless of header name casing', function() {
it('returns an array from getAll when header value is string', function() {
var headers = {
// Express concatenates repeated keys with ', '
// and also lowercases the keys
'x-test-header': 'value1, value2'
};
headers = new FastBootHeaders(headers);

expect(headers.getAll('x-test-header')).to.deep.equal(['value1, value2']);
});

it('returns an array of header values from getAll, regardless of header name casing', function() {
var headers = {
'x-test-header': ['value1', 'value2']
};
headers = new FastBootHeaders(headers);

expect(headers.getAll('X-Test-Header')).to.deep.equal(['value1', 'value2']);
expect(headers.getAll('x-test-header')).to.deep.equal(['value1', 'value2']);
});

it('returns an emtpy array when a header is not present', function() {
var headers = {
// Express concatenates repeated keys with ', '
// and also lowercases the keys
'x-test-header': 'value1, value2'
'x-test-header': ['value1', 'value2']
};
headers = new FastBootHeaders(headers);

Expand All @@ -32,9 +37,7 @@ describe('FastBootHeaders', function() {

it('returns the first value when using get, regardless of case', function() {
var headers = {
// Express concatenates repeated keys with ', '
// and also lowercases the keys
'x-test-header': 'value1, value2'
'x-test-header': ['value1', 'value2']
};
headers = new FastBootHeaders(headers);

Expand All @@ -44,9 +47,7 @@ describe('FastBootHeaders', function() {

it('returns null when using get when a header is not present', function() {
var headers = {
// Express concatenates repeated keys with ', '
// and also lowercases the keys
'x-test-header': 'value1, value2'
'x-test-header': ['value1', 'value2']
};
headers = new FastBootHeaders(headers);

Expand All @@ -56,9 +57,7 @@ describe('FastBootHeaders', function() {

it('returns whether or not a header is present via has, regardless of casing', function() {
var headers = {
// Express concatenates repeated keys with ', '
// and also lowercases the keys
'x-test-header': 'value1, value2'
'x-test-header': ['value1', 'value2']
};
headers = new FastBootHeaders(headers);

Expand Down
2 changes: 1 addition & 1 deletion test/fastboot-response-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("FastBootResponse", function() {
beforeEach(function () {
var mockResponse = {
_headers: {
"i-am-a": "mock header, me too",
"i-am-a": ["mock header", "me too"],
"cookie": ""
}
};
Expand Down