Skip to content

Commit

Permalink
Merge branch '1.x' of https://github.com/fastify/fastify into 1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
delvedor committed Jan 11, 2019
2 parents 808939c + a8c4d37 commit c22a88b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion 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.
Expand Down
2 changes: 1 addition & 1 deletion fastify.js
Expand Up @@ -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}`)
}

Expand Down
9 changes: 8 additions & 1 deletion lib/reply.js
Expand Up @@ -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
}
Expand Down
35 changes: 35 additions & 0 deletions test/internals/reply.test.js
Expand Up @@ -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'])
})
})

0 comments on commit c22a88b

Please sign in to comment.