feat: Get actual client IP from X-Forwarded-For

This commit is contained in:
ptrcnull 2022-01-22 22:48:53 +01:00
parent ec6d68154a
commit 09210f601b
Signed by: ptrcnull
GPG key ID: 411F7B30801DD9CA

View file

@ -110,6 +110,14 @@ func (h *Handler) HomepageHandler(wr http.ResponseWriter, req *http.Request) {
func (h *Handler) CreateHandler(wr http.ResponseWriter, req *http.Request) { func (h *Handler) CreateHandler(wr http.ResponseWriter, req *http.Request) {
log.Println("CreateHandler") 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() req.ParseForm()
code, err := h.GetCode(req.Form.Get("url"), req.RemoteAddr) code, err := h.GetCode(req.Form.Get("url"), req.RemoteAddr)
if err != nil { if err != nil {