From dc35391ceb026fce0db856735ad4402c8c8749d0 Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Fri, 14 Aug 2020 13:04:48 +0300 Subject: [PATCH] fix https://github.com/kataras/iris/issues/1584 --- _examples/routing/subdomains/redirect/main_test.go | 1 + context/context.go | 7 +++---- core/router/handler.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/_examples/routing/subdomains/redirect/main_test.go b/_examples/routing/subdomains/redirect/main_test.go index d790c878..9e4410cf 100644 --- a/_examples/routing/subdomains/redirect/main_test.go +++ b/_examples/routing/subdomains/redirect/main_test.go @@ -25,5 +25,6 @@ func TestSubdomainRedirectWWW(t *testing.T) { for _, test := range tests { e.GET(test.path).Expect().Status(httptest.StatusOK).Body().Equal(test.response) + e.GET(test.path).WithURL("www.mydomain.com").Expect().Status(httptest.StatusOK).Body().Equal(test.response) } } diff --git a/context/context.go b/context/context.go index 4fb8a5b3..ff27caed 100644 --- a/context/context.go +++ b/context/context.go @@ -785,12 +785,11 @@ func (ctx *Context) Host() string { // GetHost returns the host part of the current URI. func GetHost(r *http.Request) string { - if host := r.Host; host != "" { + // contains subdomain. + if host := r.URL.Host; host != "" { return host } - - // contains subdomain. - return r.URL.Host + return r.Host } // Subdomain returns the subdomain of this request, if any. diff --git a/core/router/handler.go b/core/router/handler.go index 8dd8fafc..2d038631 100644 --- a/core/router/handler.go +++ b/core/router/handler.go @@ -327,7 +327,7 @@ func canHandleSubdomain(ctx *context.Context, subdomain string) bool { return true } - requestHost := ctx.Request().URL.Host + requestHost := ctx.Host() if netutil.IsLoopbackSubdomain(requestHost) { // this fixes a bug when listening on // 127.0.0.1:8080 for example