feat: Get actual client IP from X-Forwarded-For
This commit is contained in:
parent
ec6d68154a
commit
09210f601b
1 changed files with 8 additions and 0 deletions
8
main.go
8
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 {
|
||||
|
|
Loading…
Reference in a new issue