From eed96af9bc2378a133ad49450808b593d0eb73d6 Mon Sep 17 00:00:00 2001 From: kellyselden Date: Thu, 22 Sep 2016 15:51:11 -0700 Subject: [PATCH 1/2] handle headers as both strings and arrays --- src/fastboot-headers.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/fastboot-headers.js b/src/fastboot-headers.js index 1fe2549..1e4aea0 100644 --- a/src/fastboot-headers.js +++ b/src/fastboot-headers.js @@ -5,7 +5,14 @@ function FastBootHeaders(headers) { this.headers = {}; for (var header in headers) { - this.headers[header] = headers[header].split(', '); + let value = headers[header]; + + // convert to array if not already + if (typeof value === 'string') { + value = value.split(', '); + } + + this.headers[header] = value; } } From 508e23187855681e595cd723e0fc35359012a93c Mon Sep 17 00:00:00 2001 From: kellyselden Date: Mon, 26 Sep 2016 09:40:05 -0700 Subject: [PATCH 2/2] add array header test --- test/fastboot-headers-test.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/fastboot-headers-test.js b/test/fastboot-headers-test.js index 10eb435..1f43a4e 100644 --- a/test/fastboot-headers-test.js +++ b/test/fastboot-headers-test.js @@ -68,6 +68,15 @@ describe('FastBootHeaders', function() { expect(headers.has('host')).to.be.false; }); + it('handles header values that are already an array', function() { + var headers = { + 'x-test-header': ['value1', 'value2'] + }; + headers = new FastBootHeaders(headers); + + expect(headers.getAll('x-test-header')).to.deep.equal(['value1', 'value2']); + }); + it('appends entries onto a header, regardless of casing', function() { var headers = new FastBootHeaders(); @@ -149,4 +158,3 @@ describe('FastBootHeaders', function() { expect(entriesIterator.next()).to.deep.equal({ value: undefined, done: true }); }); }); -