diff --git a/src/fastboot-headers.js b/src/fastboot-headers.js index 1fe2549..77609c1 100644 --- a/src/fastboot-headers.js +++ b/src/fastboot-headers.js @@ -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; } } diff --git a/test/fastboot-headers-test.js b/test/fastboot-headers-test.js index 041ee25..014c8a5 100644 --- a/test/fastboot-headers-test.js +++ b/test/fastboot-headers-test.js @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/test/fastboot-response-test.js b/test/fastboot-response-test.js index 304b26e..d01cd51 100644 --- a/test/fastboot-response-test.js +++ b/test/fastboot-response-test.js @@ -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": "" } };