@@ -748,19 +748,22 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
748
748
PerWriteTimeout = sec .Key ("PER_WRITE_TIMEOUT" ).MustDuration (PerWriteTimeout )
749
749
PerWritePerKbTimeout = sec .Key ("PER_WRITE_PER_KB_TIMEOUT" ).MustDuration (PerWritePerKbTimeout )
750
750
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 )
758
753
759
- // Check if has app suburl.
754
+ // Check validity of AppURL
760
755
appURL , err := url .Parse (AppURL )
761
756
if err != nil {
762
757
log .Fatal ("Invalid ROOT_URL '%s': %s" , AppURL , err )
763
758
}
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
+
764
767
// Suburl should start with '/' and end without '/', such as '/{subpath}'.
765
768
// This value is empty if site does not have sub-url.
766
769
AppSubURL = strings .TrimSuffix (appURL .Path , "/" )
0 commit comments