From 09210f601ba168b1b24c218b7807f143a1cac75c Mon Sep 17 00:00:00 2001 From: ptrcnull Date: Sat, 22 Jan 2022 22:48:53 +0100 Subject: [PATCH] feat: Get actual client IP from X-Forwarded-For --- main.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.go b/main.go index 1a08c48..d5c576f 100644 --- a/main.go +++ b/main.go @@ -110,6 +110,14 @@ func (h *Handler) HomepageHandler(wr http.ResponseWriter, req *http.Request) { func (h *Handler) CreateHandler(wr http.ResponseWriter, req *http.Request) { log.Println("CreateHandler") + ip := req.RemoteAddr + if strings.HasPrefix(ip, "127.0.0.1") { + proxyIp := strings.Split(req.Header.Get("X-Forwarded-For"), ",")[0] + if proxyIp != "" { + ip = proxyIp + } + } + req.ParseForm() code, err := h.GetCode(req.Form.Get("url"), req.RemoteAddr) if err != nil {