mirror of
https://github.com/caddyserver/caddy.git
synced 2026-07-10 19:04:22 +00:00
Add hostname template action
This adds the ability to display the remote hostname of the visitors IP with template actions.
This commit is contained in:
parent
729e4f0239
commit
92af3ee4d8
2 changed files with 43 additions and 0 deletions
|
|
@ -63,6 +63,18 @@ func (c Context) Header(name string) string {
|
|||
return c.Req.Header.Get(name)
|
||||
}
|
||||
|
||||
// Hostname gets the (remote) hostname of the client making the request.
|
||||
func (c Context) Hostname() string {
|
||||
ip := c.IP()
|
||||
|
||||
hostnameList, err := net.LookupAddr(ip)
|
||||
if err != nil || len(hostnameList) == 0 {
|
||||
return c.Req.RemoteAddr
|
||||
}
|
||||
|
||||
return hostnameList[0]
|
||||
}
|
||||
|
||||
// Env gets a map of the environment variables.
|
||||
func (c Context) Env() map[string]string {
|
||||
osEnv := os.Environ()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue