@@ -748,19 +748,22 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
748748 PerWriteTimeout = sec .Key ("PER_WRITE_TIMEOUT" ).MustDuration (PerWriteTimeout )
749749 PerWritePerKbTimeout = sec .Key ("PER_WRITE_PER_KB_TIMEOUT" ).MustDuration (PerWritePerKbTimeout )
750750
751- defaultAppURL := string (Protocol ) + "://" + Domain
752- if (Protocol == HTTP && HTTPPort != "80" ) || (Protocol == HTTPS && HTTPPort != "443" ) {
753- defaultAppURL += ":" + HTTPPort
754- }
755- AppURL = sec .Key ("ROOT_URL" ).MustString (defaultAppURL + "/" )
756- // This should be TrimRight to ensure that there is only a single '/' at the end of AppURL.
757- AppURL = strings .TrimRight (AppURL , "/" ) + "/"
751+ defaultAppURL := string (Protocol ) + "://" + Domain + ":" + HTTPPort
752+ AppURL = sec .Key ("ROOT_URL" ).MustString (defaultAppURL )
758753
759- // Check if has app suburl.
754+ // Check validity of AppURL
760755 appURL , err := url .Parse (AppURL )
761756 if err != nil {
762757 log .Fatal ("Invalid ROOT_URL '%s': %s" , AppURL , err )
763758 }
759+ // Remove default ports from AppURL.
760+ // (scheme-based URL normalization, RFC 3986 section 6.2.3)
761+ if (appURL .Scheme == string (HTTP ) && appURL .Port () == "80" ) || (appURL .Scheme == string (HTTPS ) && appURL .Port () == "443" ) {
762+ appURL .Host = appURL .Hostname ()
763+ }
764+ // This should be TrimRight to ensure that there is only a single '/' at the end of AppURL.
765+ AppURL = strings .TrimRight (appURL .String (), "/" ) + "/"
766+
764767 // Suburl should start with '/' and end without '/', such as '/{subpath}'.
765768 // This value is empty if site does not have sub-url.
766769 AppSubURL = strings .TrimSuffix (appURL .Path , "/" )
0 commit comments