From eaa3c91d51c60db00edbd1ccffd3816064b9bae1 Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" <kataras2006@hotmail.com> Date: Fri, 24 Mar 2017 12:33:53 +0200 Subject: [PATCH] Alt the port part on subdomains if 80 or 443 in order to work as expected by devs Former-commit-id: a7603e50591624c4b7a56448fe17b7b62a2de1ba --- adaptors/httprouter/httprouter.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/adaptors/httprouter/httprouter.go b/adaptors/httprouter/httprouter.go index 01d0ec0a..f24cc20f 100644 --- a/adaptors/httprouter/httprouter.go +++ b/adaptors/httprouter/httprouter.go @@ -685,6 +685,15 @@ func (mux *serveMux) getTree(method string, subdomain string) *muxTree { } func (mux *serveMux) buildHandler(pool iris.ContextPool) http.Handler { + + hostname := pool.Framework().Config.VHost + // check if VHost is mydomain.com:80 || mydomain.com:443 before serving + // means that the port part is optional and a valid client can make a request without the port. + hostPort := iris.ParsePort(hostname) + if hostPort == 80 || hostPort == 443 { + hostname = iris.ParseHostname(hostname) // remove the port part. + } + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { pool.Run(w, r, func(context *iris.Context) { routePath := context.Path() @@ -697,7 +706,6 @@ func (mux *serveMux) buildHandler(pool iris.ContextPool) http.Handler { if mux.hosts && tree.subdomain != "" { requestHost := context.Host() - hostname := context.Framework().Config.VHost // println("mux are true and tree.subdomain= " + tree.subdomain + "and hostname = " + hostname + " host = " + requestHost) if requestHost != hostname { // we have a subdomain