From 6690023555e033ea25adb1f5bbcfac85d3ac9a25 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Mon, 3 Dec 2018 13:36:11 -0500 Subject: pkg/context: use host address and apply insecure flag for go-get=1 when needed (#5305) --- pkg/context/context.go | 15 +++++++-------- pkg/setting/setting.go | 2 ++ 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'pkg') diff --git a/pkg/context/context.go b/pkg/context/context.go index 08e3b6ea..85f49cc6 100644 --- a/pkg/context/context.go +++ b/pkg/context/context.go @@ -263,13 +263,11 @@ func Contexter() macaron.Handler { branchName = repo.DefaultBranch } - // Non-80 port needs to match port number in import path as well - host := setting.Domain - if setting.HTTPPort != "80" { - host += ":" + setting.HTTPPort - } - prefix := setting.AppURL + path.Join(ownerName, repoName, "src", branchName) + insecureFlag := "" + if !strings.HasPrefix(setting.AppURL, "https://") { + insecureFlag = "--insecure " + } c.PlainText(http.StatusOK, []byte(com.Expand(` @@ -277,14 +275,15 @@ func Contexter() macaron.Handler { - go get {GoGetImport} + go get {InsecureFlag}{GoGetImport} `, map[string]string{ - "GoGetImport": path.Join(host, setting.AppSubURL, repo.FullName()), + "GoGetImport": path.Join(setting.HostAddress, setting.AppSubURL, repo.FullName()), "CloneLink": models.ComposeHTTPSCloneURL(ownerName, repoName), "GoDocDirectory": prefix + "{/dir}", "GoDocFile": prefix + "{/dir}/{file}#L{line}", + "InsecureFlag": insecureFlag, }))) return } diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index 8191e4c8..b65de982 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -61,6 +61,7 @@ var ( AppSubURLDepth int // Number of slashes AppPath string AppDataPath string + HostAddress string // AppURL without protocol and slashes // Server settings Protocol Scheme @@ -463,6 +464,7 @@ func NewContext() { // This value is empty if site does not have sub-url. AppSubURL = strings.TrimSuffix(url.Path, "/") AppSubURLDepth = strings.Count(AppSubURL, "/") + HostAddress = url.Host Protocol = SCHEME_HTTP if sec.Key("PROTOCOL").String() == "https" { -- cgit v1.2.3