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

Why is data.body stringified on request events? #24

Open
tobiasbueschel opened this issue Mar 6, 2018 · 1 comment
Open

Why is data.body stringified on request events? #24

tobiasbueschel opened this issue Mar 6, 2018 · 1 comment

Comments

@tobiasbueschel
Copy link

Thanks for all the work with this library. It's really useful :-)

One thing I have noticed is that on request events, data.body is stringified as seen here:

if (this.body) {
  data.body = this.body.toString('utf8')
}

[index.js, line: 36]

Just curious why this is done?

I have a particular use case where I want to log all outgoing requests and responses but need to obfuscate sensitive information such as passwords, tokens etc. from the log messages. Previously, my Bunyan serializer was just able to go through any body object and remove sensitive values from any keys that I declared sensitive. But as the data.body is not what it originally was when sending the request, I would have to JSON.parse(data.body) it again.

Thanks :-)

@tobiasbueschel tobiasbueschel changed the title Why is there request.body stringified? Why is data.body stringified on request events? Mar 6, 2018
@markstos
Copy link

I would imagine it's because this library is primarily about HTTP requests, and request bodies are always strings as they are sent across the HTTP protocol.

So for debugging the protocol it's useful to have the data in the form that it is actually when sent across HTTP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants