Alt the port part on subdomains if 80 or 443 in order to work as expected by devs

Former-commit-id: a7603e50591624c4b7a56448fe17b7b62a2de1ba
This commit is contained in:
Gerasimos (Makis) Maropoulos 2017-03-24 12:33:53 +02:00
parent 847a59386f
commit eaa3c91d51

View File

@ -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