|
@@ -3,6 +3,7 @@ package http
|
|
import (
|
|
import (
|
|
"context"
|
|
"context"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
|
+ "net"
|
|
"net/http"
|
|
"net/http"
|
|
"os"
|
|
"os"
|
|
"path"
|
|
"path"
|
|
@@ -26,6 +27,21 @@ func (ctx *Context) reset(req *http.Request, res http.ResponseWriter, ps map[str
|
|
ctx.req, ctx.res, ctx.params = req, res, ps
|
|
ctx.req, ctx.res, ctx.params = req, res, ps
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func (c *Context) RealIp() string {
|
|
|
|
+ if ip := c.Request().Header.Get("X-Forwarded-For"); ip != "" {
|
|
|
|
+ i := strings.IndexAny(ip, ",")
|
|
|
|
+ if i > 0 {
|
|
|
|
+ return strings.TrimSpace(ip[:i])
|
|
|
|
+ }
|
|
|
|
+ return ip
|
|
|
|
+ }
|
|
|
|
+ if ip := c.Request().Header.Get("X-Real-IP"); ip != "" {
|
|
|
|
+ return ip
|
|
|
|
+ }
|
|
|
|
+ ra, _, _ := net.SplitHostPort(c.Request().RemoteAddr)
|
|
|
|
+ return ra
|
|
|
|
+}
|
|
|
|
+
|
|
func (ctx *Context) Request() *http.Request {
|
|
func (ctx *Context) Request() *http.Request {
|
|
return ctx.req
|
|
return ctx.req
|
|
}
|
|
}
|