镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

Description

@tobiasbueschel

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 :-)

Activity

  1. changed the title [-]Why is there request.body stringified?[/-] [+]Why is data.body stringified on request events?[/+] on Mar 6, 2018
  2. markstos commented on Aug 29, 2018

    @markstos

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions