0

If I use

request.get(imageUrl).pipe(resposne)

then, does it return response with all data received from request.get() including headers and all the other data ?

S.D.
  • 29,290
  • 3
  • 79
  • 130
vidit mathur
  • 62
  • 1
  • 2
  • 8
  • Possible duplicate of [Does the .pipe() perform a memcpy in node.js?](https://stackoverflow.com/questions/35110911/does-the-pipe-perform-a-memcpy-in-node-js) – GottZ Mar 12 '18 at 07:27
  • i answered a similar question long ago with quite some details: https://stackoverflow.com/questions/35110911/does-the-pipe-perform-a-memcpy-in-node-js/35178495#35178495 – GottZ Mar 12 '18 at 07:27

2 Answers2

1

You will use pipe when you want to stream a response.

For example

request('http://google.com/doodle.png').pipe(fs.createWriteStream('doodle.png'))

Or

request.get('http://google.com/img.png').pipe(request.put('https://xxxe.com/img.png)

You don't need to use pipe in your case as response.get will also contain all information.

LuisPinto
  • 1,667
  • 1
  • 17
  • 36
0

Assuming you are using the request module.

The request is a readable stream (That's why you can use the pipe() function). The readable data in stream here is the body of HTTP response.

To get the headers and status code as well, you can listen to events:

request
  .get('http://example.com/img.png')
  .on('response', function(response) {
    console.log(response.statusCode) // 200
    console.log(response.headers['content-type']) // 'image/png'
  })
  .pipe(request.put('http://example.com/img.png'))
S.D.
  • 29,290
  • 3
  • 79
  • 130