How can we replicate the one-liner streaming behavior provided by the deprecated request package?
              
              #4642
            
            
          -
| The one-liner solution in the deprecated  req.pipe(request('http://mysite.com/doodle.png')).pipe(resp)We have a Node.js app that serves as a proxy server and uses this one-liner to forward all incoming requests to a private API server, then relay the responses back to users: const app = express();
for (const endpoint of ENDPOINT_LIST) {
  app.all(endpoint, (req, res, next) => {
    req.pipe(request(RPIVATE_API_BASE_URL + endpoint)).pipe(res).on('error', next);
  }
}However, since the  That said, it seems there’s no direct one-to-one replacement for the example above, meaning we’ll likely need to handle various edge cases manually — such as header management and other request/response handling details. I’ve looked into the example of  For  The limitations are: 
 For  fastifyServer.route({
  url: '/',
  method: 'GET',
  handler: (request, response) => {
    nodeServerUndiciClient.stream({
      path: '/',
      method: 'GET',
      opaque: response
    }, ({ opaque }) => opaque.raw)
  }
})Apart from explicitly specifying  | 
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
| There's no current possible way to replicate the exact one liner for the whole response, just for the response's body. You can extend the dispatcher with an interceptor that directly does that as part of the response body, although can be complicated to achieve given (I'm unaware how the request's pipes works exactly). You'd need to always check for headers and later pipe the response as you need. | 
Beta Was this translation helpful? Give feedback.
There's no current possible way to replicate the exact one liner for the whole response, just for the response's body.
You can extend the dispatcher with an interceptor that directly does that as part of the response body, although can be complicated to achieve given (I'm unaware how the request's pipes works exactly).
You'd need to always check for headers and later pipe the response as you need.