Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serialize headers (renamed header to headers) #16

Merged
merged 1 commit into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ The default `response` serializer. Returns an object:
```js
{
statusCode: Number,
header: Array, // The list of headers to be sent in the response.
headers: Object, // The headers to be sent in the response.
raw: Object // Non-enumerable, i.e. will not be in the output, original
// response object. This is available for subsequent serializers
// to use.
Expand Down
4 changes: 2 additions & 2 deletions lib/res.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var pinoResProto = Object.create({}, {
writable: true,
value: 0
},
header: {
headers: {
enumerable: true,
writable: true,
value: ''
Expand All @@ -35,7 +35,7 @@ Object.defineProperty(pinoResProto, rawSymbol, {
function resSerializer (res) {
const _res = Object.create(pinoResProto)
_res.statusCode = res.statusCode
_res.header = res._header
_res.headers = res._headers
_res.raw = res
return _res
}
Expand Down
19 changes: 19 additions & 0 deletions test/res.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,22 @@ test('can wrap response serializers', function (t) {
res.end()
}
})

test('res.headers is serialized', function (t) {
t.plan(1)

var server = http.createServer(handler)
server.unref()
server.listen(0, () => {
http.get(server.address(), () => {})
})

t.tearDown(() => server.close())

function handler (req, res) {
res.setHeader('x-custom', 'y')
var serialized = serializers.resSerializer(res)
t.is(serialized.headers['x-custom'], 'y')
res.end()
}
})