Skip to content

Commit

Permalink
fix parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
felixheck committed Oct 18, 2019
1 parent 0d95023 commit beab463
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/tokens-formats-presets.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ The following tokens are available by default. Partly it is possible to pass an
- `:status` - The status code of the request/response.
- `:method` - The http request method.
- `:payload` - The request payload. Just works with `options.hapiPino.logPayload = true`, it is enabled by default.
> Please enable `route.options.payload.parse` and set `route.options.payload.output` to `data` for full support of this token.
> Please set `route.options.payload.output` to `data` for full support of this token.
- `:remoteAddress` - The remote client IP address.
- `:remotePort` - The remote client port.
- `:url` - The parsed url of the request.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"scripts": {
"start": "NODE_ENV=test npm test -- -w",
"lint": "standard",
"test": "NODE_ENV=test nyc --check-coverage --lines 80 ava ./test/*.spec.js --timeout=30s",
"test": "NODE_ENV=test nyc --check-coverage --lines 80 ava ./test/index.spec.js --timeout=30s",
"coverage": "nyc report --reporter=lcov",
"ci.coverage": "nyc report --reporter=text-lcov | coveralls"
},
Expand Down
10 changes: 4 additions & 6 deletions src/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,14 @@ assign('method', (data, colors) => (
))

assign('payload', data => {
if (data.payload instanceof IncomingMessage) {
return '[IncomingMessage]'
}
const rawFormat = [Readable, IncomingMessage].find(x => data.payload instanceof x)

if (data.payload instanceof Readable) {
return '[ReadableStream]'
if (rawFormat) {
return `[${rawFormat.name}]`
}

if (data.payload instanceof Buffer) {
return '[Buffer]'
return data.payload.toString()
}

return JSON.stringify(data.payload || {})
Expand Down
4 changes: 2 additions & 2 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ test.serial.cb('listen to `response` event – buffer', (t) => {

helpers.spawn('inject', options, injection, (log) => {
t.truthy(log)
t.truthy(log.includes('POST 127.0.0.1 http://127.0.0.1:1338/response/buffer 200 [Buffer]'))
t.truthy(log.includes('POST 127.0.0.1 http://127.0.0.1:1338/response/buffer 200 {"foo":42}'))
t.end()
})
})
Expand All @@ -95,7 +95,7 @@ test.serial.cb('listen to `response` event – readable stream', (t) => {

helpers.spawn('inject', options, injection, (log) => {
t.truthy(log)
t.truthy(log.includes('POST 127.0.0.1 http://127.0.0.1:1338/response/stream 200 [ReadableStream]'))
t.truthy(log.includes('POST 127.0.0.1 http://127.0.0.1:1338/response/stream 200 [Readable]'))
t.end()
})
})
Expand Down

0 comments on commit beab463

Please sign in to comment.