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

intercepting body stream makes request.js not setting header of response #81

Open
TooBug opened this issue Sep 16, 2020 · 0 comments
Open

Comments

@TooBug
Copy link

TooBug commented Sep 16, 2020

in koa-logger, it replaces ctx.body with a Counter:

    if (length == null && body && body.readable) {
      ctx.body = body
        .pipe(counter = Counter())
        .on('error', ctx.onerror)
    }

in request.js, it will add headers to dest stream if it supports setHeader() method:

  // here, if koa-logger is used, dest.setHeader is undefined.

  if (dest.setHeader && !dest.headersSent) {
    for (var i in response.headers) {
      // If the response content is being decoded, the Content-Encoding header
      // of the response doesn't represent the piped content, so don't pass it.
      if (!self.gzip || i !== 'content-encoding') {
        dest.setHeader(i, response.headers[i])
      }
    }
    dest.statusCode = response.statusCode
  }

so, if we use ctx.body = request() and request() returns a stream, the headers from request() stream are lost.

TooBug added a commit to TooBug/logger that referenced this issue Apr 27, 2021
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

1 participant