Sindre Sorhus
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
11 additions and
0 deletions
-
index.js
-
test/gzip.js
|
|
@ -416,6 +416,10 @@ function asStream(opts) { |
|
|
|
|
|
|
|
const statusCode = res.statusCode; |
|
|
|
|
|
|
|
res.on('error', err => { |
|
|
|
proxy.emit('error', new got.ReadError(err, opts)); |
|
|
|
}); |
|
|
|
|
|
|
|
res.pipe(output); |
|
|
|
|
|
|
|
if (statusCode !== 304 && (statusCode < 200 || statusCode > 299)) { |
|
|
|
|
|
@ -66,6 +66,13 @@ test('handles gzip error', async t => { |
|
|
|
t.is(err.name, 'ReadError'); |
|
|
|
}); |
|
|
|
|
|
|
|
test('handles gzip error - stream', async t => { |
|
|
|
const err = await t.throws(getStream(got.stream(`${s.url}/corrupted`))); |
|
|
|
t.is(err.message, 'incorrect header check'); |
|
|
|
t.is(err.path, '/corrupted'); |
|
|
|
t.is(err.name, 'ReadError'); |
|
|
|
}); |
|
|
|
|
|
|
|
test('decompress option opts out of decompressing', async t => { |
|
|
|
const response = await got(s.url, {decompress: false}); |
|
|
|
t.true(Buffer.compare(response.body, gzipData) === 0); |
|
|
|