MCPcopy Create free account
hub / github.com/BryanMwangi/pine / IP

Method IP

pine.go:547–562  ·  view source on GitHub ↗

IP returns the client IP address, checking proxy headers first.

()

Source from the content-addressed store, hash-verified

545
546// IP returns the client IP address, checking proxy headers first.
547func (c *Ctx) IP() string {
548 if ip := c.Request.Header.Get("X-Real-Ip"); ip != "" {
549 return ip
550 }
551 if ip := c.Request.Header.Get("CF-Connecting-IP"); ip != "" {
552 return ip
553 }
554 if ip := c.Request.Header.Get("X-Forwarded-For"); ip != "" {
555 return strings.TrimSpace(strings.Split(ip, ",")[0])
556 }
557 ip, _, err := net.SplitHostPort(c.Request.RemoteAddr)
558 if err != nil {
559 return c.Request.RemoteAddr
560 }
561 return ip
562}
563
564// IPs returns all IP addresses from proxy headers.
565func (c *Ctx) IPs() []string {

Callers 2

mainFunction · 0.80
defaultKeyGenFunction · 0.80

Calls 1

GetMethod · 0.45

Tested by

no test coverage detected