diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2019-12-08 15:02:14 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2019-12-08 15:02:14 +0300 |
commit | 5ae747b1c800d02a4535fb1be0fdfcbc3ea0001e (patch) | |
tree | dbb89a7dc59b76cfe224cc881360d17c6250ae3a /internal/request/request_test.go | |
parent | 76b6d671858b44d026300752e4d37ea3d0a1e4bc (diff) |
Add support for the port component in the Host header
Diffstat (limited to 'internal/request/request_test.go')
-rw-r--r-- | internal/request/request_test.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/internal/request/request_test.go b/internal/request/request_test.go index e092448b..642209f0 100644 --- a/internal/request/request_test.go +++ b/internal/request/request_test.go @@ -2,6 +2,7 @@ package request import ( "net/http" + "net/http/httptest" "testing" "github.com/stretchr/testify/require" @@ -65,3 +66,23 @@ func TestWithHostAndDomain(t *testing.T) { }) } } + +func TestGetHostWithoutPort(t *testing.T) { + t.Run("when port component is provided", func(t *testing.T) { + request := httptest.NewRequest("GET", "https://example.com:443", nil) + request.Host = "my.example.com:8080" + + host := GetHostWithoutPort(request) + + require.Equal(t, "my.example.com", host) + }) + + t.Run("when port component is not provided", func(t *testing.T) { + request := httptest.NewRequest("GET", "http://example.com", nil) + request.Host = "my.example.com" + + host := GetHostWithoutPort(request) + + require.Equal(t, "my.example.com", host) + }) +} |