-
-
Notifications
You must be signed in to change notification settings - Fork 936
/
headers.js
54 lines (42 loc) · 1.44 KB
/
headers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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();
});