These are chat archives for request/request

5th
Jun 2015
Aldwin Vlasblom
@Avaq
Jun 05 2015 12:55
Hey, I'm wondering how to handle 404 when requesting an image for piping. I pipe the response into GrahpicsMagick for analysis but when 404 is returned from the server (in a non-image format), GraphicsMagick breaks my app.
If I listen to the 'response' event, I'm already too late to decide whether to pipe or not.
I guess I would have to make a HEAD request first?
追随
@zyf0330
Jun 05 2015 14:08
this may help you
@Avaq request
.get('http://google.com/img.png')
.on('response', function(response) {
console.log(response.statusCode) // 200
console.log(response.headers['content-type']) // 'image/png'
})
.pipe(request.put('http://mysite.com/img.png'))