Skip to content

Commit 53a6af2

Browse files
authored
Merge pull request #113 from kellyselden/header-array
Header array
2 parents 6243719 + 44195c8 commit 53a6af2

3 files changed

Lines changed: 26 additions & 17 deletions

File tree

src/fastboot-headers.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,17 @@ function FastBootHeaders(headers) {
55
this.headers = {};
66

77
for (var header in headers) {
8-
this.headers[header] = headers[header].split(', ');
8+
let value = headers[header];
9+
10+
// Express gives us either a string
11+
// or an array of strings if there are multiple values.
12+
// We want to support the Header spec
13+
// so we will coerce to an array always.
14+
if (typeof value === 'string') {
15+
value = [value];
16+
}
17+
18+
this.headers[header] = value;
919
}
1020
}
1121

test/fastboot-headers-test.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,28 @@ var alchemistRequire = require('broccoli-module-alchemist/require');
66
var FastBootHeaders = alchemistRequire('fastboot-headers.js');
77

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

15+
expect(headers.getAll('x-test-header')).to.deep.equal(['value1, value2']);
16+
});
17+
18+
it('returns an array of header values from getAll, regardless of header name casing', function() {
19+
var headers = {
20+
'x-test-header': ['value1', 'value2']
21+
};
22+
headers = new FastBootHeaders(headers);
23+
1724
expect(headers.getAll('X-Test-Header')).to.deep.equal(['value1', 'value2']);
1825
expect(headers.getAll('x-test-header')).to.deep.equal(['value1', 'value2']);
1926
});
2027

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

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

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

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

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

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

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

test/fastboot-response-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe("FastBootResponse", function() {
99
beforeEach(function () {
1010
var mockResponse = {
1111
_headers: {
12-
"i-am-a": "mock header, me too",
12+
"i-am-a": ["mock header", "me too"],
1313
"cookie": ""
1414
}
1515
};

0 commit comments

Comments
 (0)