summaryrefslogtreecommitdiff
path: root/admin.go
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2021-11-29 01:18:35 -0500
committerGitHub <noreply@github.com>2021-11-29 01:18:35 -0500
commitf55b123d63132e290789bcd07077375c76b6e1dd (patch)
tree494cf4f8d85f48d5d3bc3a6e12d74d491710d6cd /admin.go
parent0eb0b60f47bddcf24f6af9265e60044033555ff2 (diff)
caddyhttp: Split up logged remote address into IP and port (#4403)
Diffstat (limited to 'admin.go')
-rw-r--r--admin.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/admin.go b/admin.go
index 684526d..6960de5 100644
--- a/admin.go
+++ b/admin.go
@@ -659,11 +659,17 @@ type adminHandler struct {
// ServeHTTP is the external entry point for API requests.
// It will only be called once per request.
func (h adminHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+ ip, port, err := net.SplitHostPort(r.RemoteAddr)
+ if err != nil {
+ ip = r.RemoteAddr
+ port = ""
+ }
log := Log().Named("admin.api").With(
zap.String("method", r.Method),
zap.String("host", r.Host),
zap.String("uri", r.RequestURI),
- zap.String("remote_addr", r.RemoteAddr),
+ zap.String("remote_ip", ip),
+ zap.String("remote_port", port),
zap.Reflect("headers", r.Header),
)
if r.TLS != nil {