Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for stripping port in host header #591

Merged
merged 1 commit into from
Aug 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions test/headers.js
Original file line number Diff line number Diff line change
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});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should use remote server when we can just use our local server. Using a remote endpoint slows down the tests and makes them more fragile.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Listening on 80 or 443 is likely to crash (EACCESS)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right... We could have used nock, but I guess this is good enough then.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, I forgot about nock. I'll just push a commit.

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');
});