diff options
author | zeripath <art27@cantab.net> | 2019-05-27 22:08:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-27 22:08:38 +0100 |
commit | 69d81b656978a03ff277a611f5c3d9ef1814d001 (patch) | |
tree | 57e6bbaa990551b646dfbd3c7d965450d5754f54 /modules/context | |
parent | 9ca7fcddbb4c9aba7a3f8e84f6c63b7504837bee (diff) | |
download | gitea-69d81b656978a03ff277a611f5c3d9ef1814d001.tar.gz gitea-69d81b656978a03ff277a611f5c3d9ef1814d001.zip |
Handle insecure and ports in go get (#7041)
* Handle insecure and ports in go get
* Fix IsExternalURL for non-standard ports
Diffstat (limited to 'modules/context')
-rw-r--r-- | modules/context/context.go | 10 | ||||
-rw-r--r-- | modules/context/repo.go | 5 |
2 files changed, 13 insertions, 2 deletions
diff --git a/modules/context/context.go b/modules/context/context.go index c7534a16cd..1699d7aecc 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -257,6 +257,13 @@ func Contexter() macaron.Handler { branchName = repo.DefaultBranch } prefix := setting.AppURL + path.Join(url.PathEscape(ownerName), url.PathEscape(repoName), "src", "branch", util.PathEscapeSegments(branchName)) + + appURL, _ := url.Parse(setting.AppURL) + + insecure := "" + if appURL.Scheme == string(setting.HTTP) { + insecure = "--insecure " + } c.Header().Set("Content-Type", "text/html") c.WriteHeader(http.StatusOK) c.Write([]byte(com.Expand(`<!doctype html> @@ -266,7 +273,7 @@ func Contexter() macaron.Handler { <meta name="go-source" content="{GoGetImport} _ {GoDocDirectory} {GoDocFile}"> </head> <body> - go get {GoGetImport} + go get {Insecure}{GoGetImport} </body> </html> `, map[string]string{ @@ -274,6 +281,7 @@ func Contexter() macaron.Handler { "CloneLink": models.ComposeHTTPSCloneURL(ownerName, repoName), "GoDocDirectory": prefix + "{/dir}", "GoDocFile": prefix + "{/dir}/{file}#L{line}", + "Insecure": insecure, }))) return } diff --git a/modules/context/repo.go b/modules/context/repo.go index f9ed9327ff..0908340879 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -188,7 +188,10 @@ func RetrieveBaseRepo(ctx *Context, repo *models.Repository) { // ComposeGoGetImport returns go-get-import meta content. func ComposeGoGetImport(owner, repo string) string { - return path.Join(setting.Domain, setting.AppSubURL, url.PathEscape(owner), url.PathEscape(repo)) + /// setting.AppUrl is guaranteed to be parse as url + appURL, _ := url.Parse(setting.AppURL) + + return path.Join(appURL.Host, setting.AppSubURL, url.PathEscape(owner), url.PathEscape(repo)) } // EarlyResponseForGoGetMeta responses appropriate go-get meta with status 200 |