From d7238f3f9f00040c00d3949b58fdac177eaec9c2 Mon Sep 17 00:00:00 2001 From: Digvijay Richhariya Date: Thu, 3 Jan 2019 01:34:58 -0800 Subject: [PATCH 1/3] Fix setting multiple cookies as multiple 'Set-Cookie' headers. (fix https://github.com/fastify/fastify/issues/1358) (#1360) --- lib/reply.js | 9 ++++++++- test/internals/reply.test.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/lib/reply.js b/lib/reply.js index 533bad81ac..acc60826c3 100644 --- a/lib/reply.js +++ b/lib/reply.js @@ -129,7 +129,14 @@ Reply.prototype.header = function (key, value) { if (this._headers[_key] && _key === 'set-cookie') { // https://tools.ietf.org/html/rfc7230#section-3.2.2 - this._headers[_key] = [this._headers[_key]].concat(value) + if (typeof this._headers[_key] === 'string') { + this._headers[_key] = [this._headers[_key]] + } + if (Array.isArray(value)) { + Array.prototype.push.apply(this._headers[_key], value) + } else { + this._headers[_key].push(value) + } } else { this._headers[_key] = value } diff --git a/test/internals/reply.test.js b/test/internals/reply.test.js index 8e8ea8e52f..f429444d68 100644 --- a/test/internals/reply.test.js +++ b/test/internals/reply.test.js @@ -916,3 +916,38 @@ test('.status() is an alias for .code()', t => { t.is(res.statusCode, 418) }) }) + +test('reply.header setting multiple cookies as multiple Set-Cookie headers', t => { + t.plan(7) + + const fastify = require('../../')() + + fastify.get('/headers', function (req, reply) { + reply + .header('set-cookie', 'one') + .header('set-cookie', 'two') + .header('set-cookie', 'three') + .header('set-cookie', ['four', 'five', 'six']) + .send({}) + }) + + fastify.listen(0, err => { + t.error(err) + fastify.server.unref() + + sget({ + method: 'GET', + url: 'http://localhost:' + fastify.server.address().port + '/headers' + }, (err, response, body) => { + t.error(err) + t.ok(response.headers['set-cookie']) + t.strictDeepEqual(response.headers['set-cookie'], ['one', 'two', 'three', 'four', 'five', 'six']) + }) + }) + + fastify.inject('/headers', (error, response) => { + t.error(error) + t.ok(response.headers['set-cookie']) + t.strictDeepEqual(response.headers['set-cookie'], ['one', 'two', 'three', 'four', 'five', 'six']) + }) +}) From 7d6d7e6078644d7abaf502a444427bff88933eea Mon Sep 17 00:00:00 2001 From: Cemre Mengu Date: Fri, 4 Jan 2019 14:23:10 +0300 Subject: [PATCH 2/3] Update copyright year to 2019 (#1364) --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 4df364498f..2d9d093448 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2016-2018 The Fastify Team +Copyright (c) 2016-2019 The Fastify Team The Fastify team members are listed at https://github.com/fastify/fastify#team and in the README file. From a8c4d37f36bf72efa0fb5f94c15fc44b833dba26 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 4 Jan 2019 15:19:07 +0300 Subject: [PATCH 3/3] move ECONNRESET log from error to debug (#1363) * move ECONNRESET log from error to debug * move client errors to debug --- fastify.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastify.js b/fastify.js index 26cf76bd94..db89ecf780 100644 --- a/fastify.js +++ b/fastify.js @@ -786,7 +786,7 @@ function build (options) { message: 'Client Error', statusCode: 400 }) - log.error({ err }, 'client error') + log.debug({ err }, 'client error') socket.end(`HTTP/1.1 400 Bad Request\r\nContent-Length: ${body.length}\r\nContent-Type: application/json\r\n\r\n${body}`) }