|
|
@ -36,6 +36,7 @@ function requestAsEventEmitter(opts) { |
|
|
|
|
|
|
|
var req = fn.request(opts, function (res) { |
|
|
|
var statusCode = res.statusCode; |
|
|
|
|
|
|
|
if (isRedirect(statusCode) && 'location' in res.headers && (opts.method === 'GET' || opts.method === 'HEAD')) { |
|
|
|
res.resume(); |
|
|
|
|
|
|
@ -94,13 +95,13 @@ function asCallback(opts, cb) { |
|
|
|
|
|
|
|
ee.on('response', function (res) { |
|
|
|
readAllStream(res, opts.encoding, function (err, data) { |
|
|
|
var statusCode = res.statusCode; |
|
|
|
|
|
|
|
if (err) { |
|
|
|
cb(new got.ReadError(err, opts), null, res); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
var statusCode = res.statusCode; |
|
|
|
|
|
|
|
if (statusCode < 200 || statusCode > 299) { |
|
|
|
err = new got.HTTPError(statusCode, opts); |
|
|
|
} |
|
|
@ -176,9 +177,10 @@ function asStream(opts) { |
|
|
|
}); |
|
|
|
|
|
|
|
ee.on('response', function (res) { |
|
|
|
var statusCode = res.statusCode; |
|
|
|
|
|
|
|
proxy.setReadable(res); |
|
|
|
|
|
|
|
var statusCode = res.statusCode; |
|
|
|
if (statusCode < 200 || statusCode > 299) { |
|
|
|
proxy.emit('error', new got.HTTPError(statusCode, opts), null, res); |
|
|
|
return; |
|
|
|