How to log response headers like pino-http #4833
Unanswered
gabrieledarrigo
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm working with Adonis.js 6 and trying to log every HTTP request and response, similar to how pino-http does it.
While requests are logged correctly, responses have empty headers when using
response.response.getHeaders()
.Here are the details:
Setup: I log requests and responses using a custom middleware. To capture logs, it listens to the
finish
events on theresponse
object.Problem: Headers in the response are empty (
response.response.getHeaders()
returns{}
).However, the private property
_headers
contains the expected data.Here's the middleware code:
The middleware is configured on the Server stack.
How can I correctly access response headers without relying on
_headers
?Is there a better way to implement this logging middleware in Adonis.js?
Beta Was this translation helpful? Give feedback.
All reactions