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.
 

43 lines
1.2 KiB

import test from 'ava';
import got from '../';
import {createServer} from './_server';
const s = createServer();
s.on('/', (req, res) => {
res.end(JSON.stringify(req.headers));
});
test.before('headers - setup', t => {
s.listen(s.port, () => t.end());
});
test('headers - send user-agent header by default', async t => {
const headers = (await got(s.url, {json: true})).body;
t.is(headers['user-agent'], 'https://github.com/sindresorhus/got');
});
test('headers - send accept-encoding header by default', async t => {
const headers = (await got(s.url, {json: true})).body;
t.is(headers['accept-encoding'], 'gzip,deflate');
});
test('headers - send accept header with json option', async t => {
const headers = (await got(s.url, {json: true})).body;
t.is(headers.accept, 'application/json');
});
test('headers - send host header by default', async t => {
const headers = (await got(s.url, {json: true})).body;
t.is(headers.host, `localhost:${s.port}`);
});
test('headers - transform headers 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.after('headers - cleanup', t => {
s.close();
t.end();
});