Skip to content

Commit 426102a

Browse files
committed
fix(helpers): fix crash in formatHttpRequest
Fixes: #17
1 parent 1d684bd commit 426102a

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

helpers/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Fix possible crash in `formatHttpRequest` if `req.socket` is not available.
6+
([#17](https://github.com/elastic/ecs-logging-nodejs/issues/17))
57
- Add support for the hapi request object being passed to `formatHttpRequest`
68
and `formatHttpResponse`.
79
- Fix the setting of the remote IP and port

helpers/lib/http-formatters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function formatHttpRequest (ecs, req) {
4646
ecs.http.request.method = method.toLowerCase()
4747

4848
ecs.url = ecs.url || {}
49-
ecs.url.full = (socket.encrypted ? 'https://' : 'http://') + headers.host + url
49+
ecs.url.full = (socket && socket.encrypted ? 'https://' : 'http://') + headers.host + url
5050
const hasQuery = url.indexOf('?')
5151
const hasAnchor = url.indexOf('#')
5252
if (hasQuery > -1 && hasAnchor > -1) {

0 commit comments

Comments
 (0)