I'm creating a request using the request npm module. However in case the content type is not json, i want the stream to stop. At the moment, it does not stop and and error is generated because unzip reads an invalid header.. How can we stop a stream?
var req = request(options)
req
.on('error', function (err) { console.log("err"); reject(err) })
.on('response', function(response) {
if(response.headers['content-type'] != 'application/json')
{
console.log(response.headers['content-type'])
req.destroy() // doesn't work
this.destroy() // doesn't work
}
})
.on('end', function () { resolve() })
.pipe(gunzip) // ERROR!
you can use stream.pause() as follows:
var req = request(options)
req
.on('error', function (err) { console.log("err"); reject(err) })
.on('response', function(response) {
if(response.headers['content-type'] != 'application/json')
{
console.log(response.headers['content-type'])
req.pause(); // stream paused
reject('not json');
}
})
.on('end', function () { resolve() })
.pipe(gunzip)
Google PHP Api Client - I keep getting Error 401: UNAUTHENTICATED
Getting data from nested fields using mongoDB and php driver manager
How to update photo in Active Directory using PHP ldap_modify
Turning off multiple WordPress menu items for email addresses
I want to use Shutterstock API in my website, but access it via my country's IPs is not possible;
When I'm connecting to database in node, I have to add db name, username, password etcIf I'm right every user can access js file, when he knows address
Hi Have the following code which populates bootstrap table
I created a media query for phones with 414px width size and less or iPhone 6 plus "portrait"I am trying to make a drop down menu and I got everything to work, its just the navigation bar is not moving