Skip to content

Commit c36e5ea

Browse files
author
kellyselden
committed
header value coerce to array instead of split
1 parent 6243719 commit c36e5ea

3 files changed

Lines changed: 17 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: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ var FastBootHeaders = alchemistRequire('fastboot-headers.js');
88
describe('FastBootHeaders', function() {
99
it('returns an array of header values from getAll, regardless of header name casing', function() {
1010
var headers = {
11-
// Express concatenates repeated keys with ', '
12-
// and also lowercases the keys
13-
'x-test-header': 'value1, value2'
11+
'x-test-header': ['value1', 'value2']
1412
};
1513
headers = new FastBootHeaders(headers);
1614

@@ -20,9 +18,7 @@ describe('FastBootHeaders', function() {
2018

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

@@ -32,9 +28,7 @@ describe('FastBootHeaders', function() {
3228

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

@@ -44,9 +38,7 @@ describe('FastBootHeaders', function() {
4438

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

@@ -56,9 +48,7 @@ describe('FastBootHeaders', function() {
5648

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

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)