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>
This commit is contained in:
Wim 2020-07-26 22:31:28 +02:00 committed by GitHub
parent 415fc8288f
commit 4609eba2e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 9 deletions

View file

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