diff options
author | Wim <wim@42.be> | 2020-07-26 22:31:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-26 16:31:28 -0400 |
commit | 4609eba2e7683acde13231fb02747e3b2e09ff45 (patch) | |
tree | 42982792623d4a77a9783a7e222a2d98dd329741 /modules/setting | |
parent | 415fc8288ff9c83c99939003657db3c6ac978a3e (diff) | |
download | gitea-4609eba2e7683acde13231fb02747e3b2e09ff45.tar.gz gitea-4609eba2e7683acde13231fb02747e3b2e09ff45.zip |
Fix ipv6 parsing (#12321)
* Fix ipv6 parsing
* Update modules/setting/setting.go
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'modules/setting')
-rw-r--r-- | modules/setting/setting.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 4c2fba8048..199f27a21f 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -626,8 +626,10 @@ func NewContext() { StaticURLPrefix = strings.TrimSuffix(sec.Key("STATIC_URL_PREFIX").MustString(AppSubURL), "/") AppSubURLDepth = strings.Count(AppSubURL, "/") // Check if Domain differs from AppURL domain than update it to AppURL's domain - // TODO: Can be replaced with url.Hostname() when minimal GoLang version is 1.8 - urlHostname := strings.SplitN(appURL.Host, ":", 2)[0] + urlHostname, _, err := net.SplitHostPort(appURL.Host) + if err != nil { + log.Fatal("Invalid host in ROOT_URL '%s': %s", appURL.Host, err) + } if urlHostname != Domain && net.ParseIP(urlHostname) == nil { Domain = urlHostname } @@ -643,11 +645,10 @@ func NewContext() { default: defaultLocalURL = string(Protocol) + "://" if HTTPAddr == "0.0.0.0" { - defaultLocalURL += "localhost" + defaultLocalURL += net.JoinHostPort("localhost", HTTPPort) + "/" } else { - defaultLocalURL += HTTPAddr + defaultLocalURL += net.JoinHostPort(HTTPAddr, HTTPPort) + "/" } - defaultLocalURL += ":" + HTTPPort + "/" } LocalURL = sec.Key("LOCAL_ROOT_URL").MustString(defaultLocalURL) RedirectOtherPort = sec.Key("REDIRECT_OTHER_PORT").MustBool(false) |