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

Response body as a buffer instead of string #485

Open
pedrorfernandes opened this issue Apr 15, 2023 · 2 comments
Open

Response body as a buffer instead of string #485

pedrorfernandes opened this issue Apr 15, 2023 · 2 comments

Comments

@pedrorfernandes
Copy link

At the moment response bodies are parsed as a string:

addBody (data) {
    const req = this.peek()
    if (req) {
      req.body += data
    }
  }

The issue with this is for example, if responses are gziped or if they have special characters, e.g: ’ –, then the response will be broken because special character information is lost when converting to a string.

However, verifyBody(), expectBody() and onResponse() all offer the body as string, how should we deal with this change?

  • Cause a breaking change, forcing users to migrate to a Buffer instead of a string
    • verifyBody(), expectBody() would compare buffers instead of strings
  • Convert the body to a string before calling verifyBody(), expectBody() and onResponse(), and offer BodyBuffer as a new parameter
  • Other possibilities?
@mcollina
Copy link
Owner

mcollina commented May 3, 2023

Strings are significantly faster than buffers: we'd have to use a bl to manipulate the them.

I'm ok with the breaking change, I think it's the safest bet.

@vidhan63-soe
Copy link

Converting the body to a string before comparison offers the advantage of resolving special character and encoding concerns, all while retaining the familiarity of string representation. However, this approach might not be optimal for handling large data due to potential memory inefficiency and the possibility of encountering parsing issues.

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

3 participants