@ -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" ) ;
@ -30,6 +30,8 @@ debugResponse = debug("bhttp:response");
extend = require ( "extend" ) ;
devNull = require ( "dev-null" ) ;
formData = require ( "form-data2" ) ;
concatStream = require ( "concat-stream" ) ;
@ -487,7 +489,7 @@ processResponse = function(request, response, requestState) {
}
}
} else if ( request . responseOptions . discardResponse ) {
response . resume( ) ;
response . pipe( devNull ( ) ) ;
return Promise . resolve ( response ) ;
} else {
totalBytes = response . headers [ "content-length" ] ;
@ -505,8 +507,28 @@ processResponse = function(request, response, requestState) {
} ) ;
}
return new Promise ( function ( resolve , reject ) {
response . pipe ( progressStream ) ;
response . pause ( ) ;
var attachProgressStream , _on , _progressStreamAttached , _resume ;
_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 ) {
return resolve ( response ) ;
} else {
@ -573,7 +595,7 @@ redirectUnchanged = function(request, response, requestState) {
doRedirect = function ( request , response , requestState , newOptions ) {
return Promise [ "try" ] ( function ( ) {
if ( ! request . responseOptions . keepRedirectResponses ) {
response . resume( ) ;
response . pipe( devNull ( ) ) ;
}
requestState . redirectHistory . push ( response ) ;
return bhttpAPI . _doRequest ( response . headers [ "location" ] , newOptions , requestState ) ;