Skip to content

Commit

Permalink
Add tests for stripping port in host header (sindresorhus#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Aug 28, 2018
1 parent deeb0b7 commit 7eeb352
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/headers.js
Expand Up @@ -178,3 +178,28 @@ test('non-existent headers set to undefined are omitted', async t => {
const headers = JSON.parse(body);
t.false(Reflect.has(headers, 'blah'));
});

test('preserve port in host header if non-standard port', async t => {
const {body} = await got(s.url, {json: true});
t.is(body.host, 'localhost:' + s.port);
});

test('strip port in host header if explicit standard port (:80) & protocol (HTTP)', async t => {
const {body} = await got('http://httpbin.org:80/headers', {json: true});
t.is(body.headers.Host, 'httpbin.org');
});

test('strip port in host header if explicit standard port (:443) & protocol (HTTPS)', async t => {
const {body} = await got('https://httpbin.org:443/headers', {json: true});
t.is(body.headers.Host, 'httpbin.org');
});

test('strip port in host header if implicit standard port & protocol (HTTP)', async t => {
const {body} = await got('http://httpbin.org/headers', {json: true});
t.is(body.headers.Host, 'httpbin.org');
});

test('strip port in host header if implicit standard port & protocol (HTTPS)', async t => {
const {body} = await got('https://httpbin.org/headers', {json: true});
t.is(body.headers.Host, 'httpbin.org');
});

0 comments on commit 7eeb352

Please sign in to comment.