Comparing version 0.4.2-beta1 to 0.4.2
@@ -67,2 +67,3 @@ 'use strict'; | ||
`has timed out after ${requestConfig.timeout}msec`); | ||
error.name = 'TimeoutError'; | ||
httpRequest.emit('error', error); | ||
@@ -69,0 +70,0 @@ httpRequest.abort(); |
@@ -5,3 +5,2 @@ 'use strict'; | ||
const p = require('./utils/promise'); | ||
const zlib = require('zlib'); | ||
@@ -18,22 +17,7 @@ const DEFAULT_MAX_BUFFER_SIZE = 256 * 1024; | ||
this._httpResponse = httpResponse; | ||
this._stream = this._getDecompressedStream(); | ||
this.httpResponse = httpResponse; | ||
} | ||
_getDecompressedStream() { | ||
const contentEncoding = this.headers['content-encoding']; | ||
if (contentEncoding === 'gzip' || contentEncoding === 'deflate') { | ||
delete this.headers['content-encoding']; | ||
const unzipper = zlib.createUnzip(); | ||
this._httpResponse.on('error', (err) => unzipper.emit('error', err)); | ||
this._httpResponse.pipe(unzipper); | ||
return unzipper; | ||
} else { | ||
return this._httpResponse; | ||
} | ||
} | ||
getHeader(name) { | ||
return this._httpResponse.headers[name.toLowerCase()]; | ||
return this.httpResponse.headers[name.toLowerCase()]; | ||
} | ||
@@ -68,9 +52,9 @@ | ||
return new p.Promise((resolve, reject) => { | ||
this._stream.once('error', reject); | ||
this._stream.once('end', () => { | ||
this.httpResponse.once('error', reject); | ||
this.httpResponse.once('end', () => { | ||
resolve(Buffer.concat(chunks)); | ||
}); | ||
this._stream.on('data', (chunk) => { | ||
this.httpResponse.on('data', (chunk) => { | ||
if (byteCount + chunk.length > maxSize) { | ||
return this._httpResponse.destroy(new Error('Overflow response body')); | ||
return this.httpResponse.destroy(new Error('Overflow response body')); | ||
} | ||
@@ -80,3 +64,3 @@ byteCount += chunk.length; | ||
}); | ||
this._stream.resume(); | ||
this.httpResponse.resume(); | ||
}); | ||
@@ -105,3 +89,3 @@ } | ||
digest(algorithm) { | ||
const hash = this._stream.pipe(crypto.createHash(algorithm)); | ||
const hash = this.httpResponse.pipe(crypto.createHash(algorithm)); | ||
return new p.Promise((resolve) => { | ||
@@ -121,5 +105,5 @@ hash.once('readable', () => { | ||
return new p.Promise((resolve, reject) => { | ||
this._stream.on('end', () => resolve(this)); | ||
this._stream.on('error', reject); | ||
this._stream.pipe(into, opts); | ||
this.httpResponse.on('end', () => resolve(this)); | ||
this.httpResponse.on('error', reject); | ||
this.httpResponse.pipe(into, opts); | ||
}); | ||
@@ -135,5 +119,5 @@ } | ||
return new p.Promise((resolve, reject) => { | ||
this._stream.on('end', () => resolve(this)); | ||
this._stream.on('error', reject); | ||
this._stream.resume(); | ||
this.httpResponse.on('end', () => resolve(this)); | ||
this.httpResponse.on('error', reject); | ||
this.httpResponse.resume(); | ||
}); | ||
@@ -140,0 +124,0 @@ } |
{ | ||
"name": "httplease", | ||
"version": "0.4.2-beta1", | ||
"version": "0.4.2", | ||
"description": "HTTP client library with support for pluggable filters, including Zipkin, ASAP, etc", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
29778
686