ClientIP gets the IP address of the real client making the request if the request is trusted (see trusted_proxies), otherwise returns the connection's remote IP.
()
| 290 | // if the request is trusted (see trusted_proxies), otherwise returns |
| 291 | // the connection's remote IP. |
| 292 | func (c TemplateContext) ClientIP() string { |
| 293 | address := caddyhttp.GetVar(c.Req.Context(), caddyhttp.ClientIPVarKey).(string) |
| 294 | clientIP, _, err := net.SplitHostPort(address) |
| 295 | if err != nil { |
| 296 | clientIP = address // no port |
| 297 | } |
| 298 | return clientIP |
| 299 | } |
| 300 | |
| 301 | // Host returns the hostname portion of the Host header |
| 302 | // from the HTTP request. |