@ -1,4 +1,4 @@
var Promise , S , addErrorData , bhttpAPI , bhttpErrors , concatStream , createCookieJar , debug , debugRequest , debugResponse , d oPayloadRequest, doRedirect , errors , extend , formData , formFixArray , http , https , isStream , makeRequest , ofTypes , packageConfig , prepareCleanup , prepareDefaults , prepareOptions , preparePayload , prepareProtocol , prepareRequest , prepareSession , prepareUrl , processResponse , querystring , redirectGet , redirectUnchanged , sink , spy , stream , streamLength , toughCookie , urlUtil , util , _ ;
var Promise , S , addErrorData , bhttpAPI , bhttpErrors , concatStream , createCookieJar , debug , debugRequest , debugResponse , d evNull, d oPayloadRequest, doRedirect , errors , extend , formData , formFixArray , http , https , isStream , makeRequest , ofTypes , packageConfig , prepareCleanup , prepareDefaults , prepareOptions , preparePayload , prepareProtocol , prepareRequest , prepareSession , prepareUrl , processResponse , querystring , redirectGet , redirectUnchanged , sink , spy , stream , streamLength , toughCookie , urlUtil , util , _ ;
urlUtil = require ( "url" ) ;
urlUtil = require ( "url" ) ;
@ -30,6 +30,8 @@ debugResponse = debug("bhttp:response");
extend = require ( "extend" ) ;
extend = require ( "extend" ) ;
devNull = require ( "dev-null" ) ;
formData = require ( "form-data2" ) ;
formData = require ( "form-data2" ) ;
concatStream = require ( "concat-stream" ) ;
concatStream = require ( "concat-stream" ) ;
@ -487,7 +489,7 @@ processResponse = function(request, response, requestState) {
}
}
}
}
} else if ( request . responseOptions . discardResponse ) {
} else if ( request . responseOptions . discardResponse ) {
response . resume( ) ;
response . pipe( devNull ( ) ) ;
return Promise . resolve ( response ) ;
return Promise . resolve ( response ) ;
} else {
} else {
totalBytes = response . headers [ "content-length" ] ;
totalBytes = response . headers [ "content-length" ] ;
@ -505,8 +507,28 @@ processResponse = function(request, response, requestState) {
} ) ;
} ) ;
}
}
return new Promise ( function ( resolve , reject ) {
return new Promise ( function ( resolve , reject ) {
response . pipe ( progressStream ) ;
var attachProgressStream , _on , _progressStreamAttached , _resume ;
response . pause ( ) ;
_resume = response . resume . bind ( response ) ;
_on = response . on . bind ( response ) ;
_progressStreamAttached = false ;
attachProgressStream = function ( ) {
if ( ! _progressStreamAttached ) {
debugResponse ( "attaching progress stream" ) ;
_progressStreamAttached = true ;
return response . pipe ( progressStream ) ;
}
} ;
response . on = function ( eventName , handler ) {
debugResponse ( "'on' called, " + eventName ) ;
if ( eventName === "data" || eventName === "readable" ) {
attachProgressStream ( ) ;
}
return _on ( eventName , handler ) ;
} ;
response . resume = function ( ) {
attachProgressStream ( ) ;
return _resume ( ) ;
} ;
if ( request . responseOptions . stream ) {
if ( request . responseOptions . stream ) {
return resolve ( response ) ;
return resolve ( response ) ;
} else {
} else {
@ -573,7 +595,7 @@ redirectUnchanged = function(request, response, requestState) {
doRedirect = function ( request , response , requestState , newOptions ) {
doRedirect = function ( request , response , requestState , newOptions ) {
return Promise [ "try" ] ( function ( ) {
return Promise [ "try" ] ( function ( ) {
if ( ! request . responseOptions . keepRedirectResponses ) {
if ( ! request . responseOptions . keepRedirectResponses ) {
response . resume( ) ;
response . pipe( devNull ( ) ) ;
}
}
requestState . redirectHistory . push ( response ) ;
requestState . redirectHistory . push ( response ) ;
return bhttpAPI . _doRequest ( response . headers [ "location" ] , newOptions , requestState ) ;
return bhttpAPI . _doRequest ( response . headers [ "location" ] , newOptions , requestState ) ;