summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmd/web.go3
-rw-r--r--models/repo.go16
-rw-r--r--modules/setting/setting.go11
3 files changed, 21 insertions, 9 deletions
diff --git a/cmd/web.go b/cmd/web.go
index 243b9a4108..6efadb9419 100644
--- a/cmd/web.go
+++ b/cmd/web.go
@@ -7,6 +7,7 @@ package cmd
import (
"context"
"fmt"
+ "net"
"net/http"
_ "net/http/pprof" // Used for debugging if enabled and a web server is running
"os"
@@ -156,7 +157,7 @@ func runWeb(ctx *cli.Context) error {
listenAddr := setting.HTTPAddr
if setting.Protocol != setting.UnixSocket && setting.Protocol != setting.FCGIUnix {
- listenAddr += ":" + setting.HTTPPort
+ listenAddr = net.JoinHostPort(listenAddr, setting.HTTPPort)
}
log.Info("Listen: %v://%s%s", setting.Protocol, listenAddr, setting.AppSubURL)
diff --git a/models/repo.go b/models/repo.go
index 36662825c5..b2b6e1a26f 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -17,6 +17,7 @@ import (
_ "image/jpeg"
"image/png"
"io/ioutil"
+ "net"
"net/url"
"os"
"path"
@@ -969,12 +970,21 @@ func (repo *Repository) cloneLink(isWiki bool) *CloneLink {
}
cl := new(CloneLink)
+
+ // if we have a ipv6 literal we need to put brackets around it
+ // for the git cloning to work.
+ sshDomain := setting.SSH.Domain
+ ip := net.ParseIP(setting.SSH.Domain)
+ if ip != nil && ip.To4() == nil {
+ sshDomain = "[" + setting.SSH.Domain + "]"
+ }
+
if setting.SSH.Port != 22 {
- cl.SSH = fmt.Sprintf("ssh://%s@%s:%d/%s/%s.git", sshUser, setting.SSH.Domain, setting.SSH.Port, repo.OwnerName, repoName)
+ cl.SSH = fmt.Sprintf("ssh://%s@%s/%s/%s.git", sshUser, net.JoinHostPort(setting.SSH.Domain, strconv.Itoa(setting.SSH.Port)), repo.OwnerName, repoName)
} else if setting.Repository.UseCompatSSHURI {
- cl.SSH = fmt.Sprintf("ssh://%s@%s/%s/%s.git", sshUser, setting.SSH.Domain, repo.OwnerName, repoName)
+ cl.SSH = fmt.Sprintf("ssh://%s@%s/%s/%s.git", sshUser, sshDomain, repo.OwnerName, repoName)
} else {
- cl.SSH = fmt.Sprintf("%s@%s:%s/%s.git", sshUser, setting.SSH.Domain, repo.OwnerName, repoName)
+ cl.SSH = fmt.Sprintf("%s@%s:%s/%s.git", sshUser, sshDomain, repo.OwnerName, repoName)
}
cl.HTTPS = ComposeHTTPSCloneURL(repo.OwnerName, repoName)
return cl
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)