aboutsummaryrefslogtreecommitdiffstats
path: root/modules/httplib
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2025-01-07 13:17:44 +0800
committerGitHub <noreply@github.com>2025-01-07 13:17:44 +0800
commit34dfc25b8311117ae83f1c070ce4a6114ffe2843 (patch)
tree4448035e2e5628234f2de2ff48c834824b9345cf /modules/httplib
parent98637fe76e70d8b963827354b2eed2e8f151ebd6 (diff)
downloadgitea-34dfc25b8311117ae83f1c070ce4a6114ffe2843.tar.gz
gitea-34dfc25b8311117ae83f1c070ce4a6114ffe2843.zip
Make git clone URL could use current signed-in user (#33091)
close #33086 * Add a special value for "SSH_USER" setting: `(DOER_USERNAME)` * Improve parseRepositoryURL and add tests (now it doesn't have hard dependency on some setting values) Many changes are just adding "ctx" and "doer" argument to functions. By the way, improve app.example.ini, remove all `%(key)s` syntax, it only makes messy and no user really cares about it. Document: https://gitea.com/gitea/docs/pulls/138
Diffstat (limited to 'modules/httplib')
-rw-r--r--modules/httplib/url.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/modules/httplib/url.go b/modules/httplib/url.go
index e3bad1e5fb..f543c09190 100644
--- a/modules/httplib/url.go
+++ b/modules/httplib/url.go
@@ -5,6 +5,7 @@ package httplib
import (
"context"
+ "net"
"net/http"
"net/url"
"strings"
@@ -81,6 +82,12 @@ func GuessCurrentHostURL(ctx context.Context) string {
return reqScheme + "://" + req.Host
}
+func GuessCurrentHostDomain(ctx context.Context) string {
+ _, host, _ := strings.Cut(GuessCurrentHostURL(ctx), "://")
+ domain, _, _ := net.SplitHostPort(host)
+ return util.IfZero(domain, host)
+}
+
// MakeAbsoluteURL tries to make a link to an absolute URL:
// * If link is empty, it returns the current app URL.
// * If link is absolute, it returns the link.
@@ -105,7 +112,7 @@ func IsCurrentGiteaSiteURL(ctx context.Context, s string) bool {
if cleanedPath == "" || cleanedPath == "." {
u.Path = "/"
} else {
- u.Path += "/" + cleanedPath + "/"
+ u.Path = "/" + cleanedPath + "/"
}
}
if urlIsRelative(s, u) {