From d0757da6630e0d15e3aa6c9f54afdab411ca6998 Mon Sep 17 00:00:00 2001 From: Szymon Marczak <36894700+szmarczak@users.noreply.github.com> Date: Sat, 25 Aug 2018 20:47:15 +0200 Subject: [PATCH] Add tests for stripping port in `host` header (#591) Fixes #588 --- test/headers.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/headers.js b/test/headers.js index 574ed8b36..1f74f4064 100644 --- a/test/headers.js +++ b/test/headers.js @@ -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'); +});