From e3558567b2ea9326a45895e7b921b2b45e0d3fc4 Mon Sep 17 00:00:00 2001 From: j2rong4cn <253551464@qq.com> Date: Sat, 15 Jun 2024 16:10:57 +0800 Subject: [PATCH] refactor --- server/common/base.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/server/common/base.go b/server/common/base.go index b414344b413..7be4946a95e 100644 --- a/server/common/base.go +++ b/server/common/base.go @@ -21,9 +21,9 @@ func GetApiUrl(r *http.Request) string { if r.TLS != nil || r.Header.Get("X-Forwarded-Proto") == "https" { protocol = "https" } - host := r.Host - if r.Header.Get("X-Forwarded-Host") != "" { - host = r.Header.Get("X-Forwarded-Host") + host := r.Header.Get("X-Forwarded-Host") + if host == "" { + host = r.Host } api = fmt.Sprintf("%s://%s", protocol, stdpath.Join(host, api)) } @@ -32,9 +32,8 @@ func GetApiUrl(r *http.Request) string { } func GetApiUrlFromContext(ctx context.Context) string { - var r *http.Request if c, ok := ctx.(*gin.Context); ok { - r = c.Request + return GetApiUrl(c.Request) } - return GetApiUrl(r) + return GetApiUrl(nil) }