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.
70 lines
1.5 KiB
70 lines
1.5 KiB
import test from 'ava';
|
|
import got from '../';
|
|
import pkg from '../package.json';
|
|
import {createServer} from './helpers/server';
|
|
|
|
let s;
|
|
|
|
test.before('setup', async () => {
|
|
s = await createServer();
|
|
|
|
s.on('/', (req, res) => {
|
|
req.resume();
|
|
res.end(JSON.stringify(req.headers));
|
|
});
|
|
|
|
await s.listen(s.port);
|
|
});
|
|
|
|
test('user-agent', async t => {
|
|
const headers = (await got(s.url, {json: true})).body;
|
|
t.is(headers['user-agent'], `${pkg.name}/${pkg.version} (https://github.com/sindresorhus/got)`);
|
|
});
|
|
|
|
test('accept-encoding', async t => {
|
|
const headers = (await got(s.url, {json: true})).body;
|
|
t.is(headers['accept-encoding'], 'gzip,deflate');
|
|
});
|
|
|
|
test('accept header with json option', async t => {
|
|
let headers = (await got(s.url, {json: true})).body;
|
|
t.is(headers.accept, 'application/json');
|
|
|
|
headers = (await got(s.url, {
|
|
headers: {
|
|
accept: ''
|
|
},
|
|
json: true
|
|
})).body;
|
|
t.is(headers.accept, '');
|
|
});
|
|
|
|
test('host', async t => {
|
|
const headers = (await got(s.url, {json: true})).body;
|
|
t.is(headers.host, `localhost:${s.port}`);
|
|
});
|
|
|
|
test('transform names to lowercase', async t => {
|
|
const headers = (await got(s.url, {
|
|
headers: {
|
|
'USER-AGENT': 'test'
|
|
},
|
|
json: true
|
|
})).body;
|
|
t.is(headers['user-agent'], 'test');
|
|
});
|
|
|
|
test('zero content-length', async t => {
|
|
const headers = (await got(s.url, {
|
|
headers: {
|
|
'content-length': 0
|
|
},
|
|
body: 'sup',
|
|
json: true
|
|
})).body;
|
|
t.is(headers['content-length'], '0');
|
|
});
|
|
|
|
test.after('cleanup', async () => {
|
|
await s.close();
|
|
});
|
|
|