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.

54 lines
1.4 KiB

import test from 'ava';
import got from '../';
import {createServer} from './_server';
let s;
test.before('setup', async t => {
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'], '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 t => {
await s.close();
});