MCPcopy
hub / github.com/labstack/echo / RealIP

Method RealIP

context.go:249–257  ·  view source on GitHub ↗

RealIP returns the client IP address using the configured extraction strategy. If Echo#IPExtractor is set, it is used to resolve the client IP from the incoming request (typically via proxy headers such as X-Forwarded-For or X-Real-IP). Look into the `ip.go` file for comments and examples. See: -

()

Source from the content-addressed store, hash-verified

247// - No validation or trust enforcement is performed unless implemented by the configured IPExtractor.
248// - When relying on proxy headers, ensure the application is deployed behind trusted intermediaries to avoid spoofing.
249func (c *Context) RealIP() string {
250 if c.echo != nil && c.echo.IPExtractor != nil {
251 return c.echo.IPExtractor(c.request)
252 }
253 // req.RemoteAddr is the IP address of the remote end of the connection, which may be a proxy. It is populated by the
254 // http.conn.readRequest() method and uses net.Conn.RemoteAddr().String() which we trust.
255 ra, _, _ := net.SplitHostPort(c.request.RemoteAddr)
256 return ra
257}
258
259// Path returns the registered path for the handler.
260func (c *Context) Path() string {

Callers 5

TestContext_RealIPFunction · 0.95
ToMiddlewareMethod · 0.80
ToMiddlewareMethod · 0.80
rate_limiter.goFile · 0.80

Calls

no outgoing calls

Tested by 2

TestContext_RealIPFunction · 0.76