IPs returns all IP addresses from proxy headers.
()
| 563 | |
| 564 | // IPs returns all IP addresses from proxy headers. |
| 565 | func (c *Ctx) IPs() []string { |
| 566 | if ips := c.Request.Header.Get("X-Real-Ip"); ips != "" { |
| 567 | return strings.Split(ips, ",") |
| 568 | } |
| 569 | if ips := c.Request.Header.Get("CF-Connecting-IP"); ips != "" { |
| 570 | return strings.Split(ips, ",") |
| 571 | } |
| 572 | if ips := c.Request.Header.Get("X-Forwarded-For"); ips != "" { |
| 573 | return strings.Split(ips, ",") |
| 574 | } |
| 575 | ip, _, err := net.SplitHostPort(c.Request.RemoteAddr) |
| 576 | if err != nil { |
| 577 | return []string{c.Request.RemoteAddr} |
| 578 | } |
| 579 | return []string{ip} |
| 580 | } |
| 581 | |
| 582 | // RemoteAddr returns the raw remote address of the client. |
| 583 | func (c *Ctx) RemoteAddr() string { |