mirror of https://github.com/lukechilds/got.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.2 KiB
57 lines
1.2 KiB
10 years ago
|
import zlib from 'zlib';
|
||
|
import test from 'ava';
|
||
|
import got from '../';
|
||
10 years ago
|
import {createServer} from './_server';
|
||
10 years ago
|
|
||
|
const s = createServer();
|
||
|
const testContent = 'Compressible response content.\n';
|
||
|
|
||
|
s.on('/', (req, res) => {
|
||
10 years ago
|
res.statusCode = 200;
|
||
|
res.setHeader('Content-Type', 'text/plain');
|
||
10 years ago
|
res.setHeader('Content-Encoding', 'gzip');
|
||
10 years ago
|
zlib.gzip(testContent, (_, data) => res.end(data));
|
||
10 years ago
|
});
|
||
10 years ago
|
|
||
10 years ago
|
s.on('/corrupted', (req, res) => {
|
||
10 years ago
|
res.statusCode = 200;
|
||
|
res.setHeader('Content-Type', 'text/plain');
|
||
|
res.setHeader('Content-Encoding', 'gzip');
|
||
|
res.end('Not gzipped content');
|
||
10 years ago
|
});
|
||
|
|
||
10 years ago
|
test.before('gzip - setup', t => {
|
||
|
s.listen(s.port, () => t.end());
|
||
10 years ago
|
});
|
||
|
|
||
10 years ago
|
test('gzip - ungzip content', t => {
|
||
|
got(s.url, (err, data) => {
|
||
10 years ago
|
t.ifError(err);
|
||
|
t.is(data, testContent);
|
||
10 years ago
|
t.end();
|
||
|
});
|
||
|
});
|
||
|
|
||
10 years ago
|
test('gzip - ungzip error', t => {
|
||
|
got(`${s.url}/corrupted`, err => {
|
||
10 years ago
|
t.ok(err);
|
||
10 years ago
|
t.is(err.message, 'incorrect header check');
|
||
|
t.is(err.path, '/corrupted');
|
||
|
t.is(err.name, 'ReadError');
|
||
10 years ago
|
t.end();
|
||
|
});
|
||
|
});
|
||
|
|
||
10 years ago
|
test('gzip - preserve headers property', t => {
|
||
|
got(s.url, (err, data, res) => {
|
||
10 years ago
|
t.ifError(err);
|
||
10 years ago
|
t.ok(res.headers);
|
||
|
t.end();
|
||
|
});
|
||
|
});
|
||
|
|
||
10 years ago
|
test.after('gzip - cleanup', t => {
|
||
10 years ago
|
s.close();
|
||
|
t.end();
|
||
|
});
|