From 7e3b2e189b7e5340bd388f1f49fac0be1eac1a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Mon, 31 Mar 2025 01:54:29 +0900 Subject: [PATCH] feat(proxy): remove localhost judgement --- procuratio.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/procuratio.go b/procuratio.go index c7f32b8..252313c 100644 --- a/procuratio.go +++ b/procuratio.go @@ -96,17 +96,13 @@ func (g *Gemini) handler(w http.ResponseWriter, r *http.Request) { // extractIP parse real IP addr to r.RemoteAddr from proxy func extractIP(r *http.Request) { raddr := r.RemoteAddr - if strings.Contains(raddr, "127.0.0.1") || - strings.Contains(raddr, "localhost") || - strings.Contains(raddr, "@") { - realr := r.Header.Get("X-Forwarded-For") + realr := r.Header.Get("X-Forwarded-For") + if len(realr) > 0 && !strings.Contains(realr, "@") { + raddr = realr + } else { + realr = r.Header.Get("X-Real-IP") if len(realr) > 0 && !strings.Contains(realr, "@") { raddr = realr - } else { - realr = r.Header.Get("X-Real-IP") - if len(realr) > 0 && !strings.Contains(realr, "@") { - raddr = realr - } } } r.RemoteAddr = raddr