From c7d6901da66d20d75f292372bfe859c3e1650cc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kadir=20G=C3=BCn?= Date: Wed, 1 Oct 2025 17:29:51 +0300 Subject: [PATCH] Add LocalAddr method to Context for retrieving local connection address --- context.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/context.go b/context.go index 30d64cd..117e6e5 100644 --- a/context.go +++ b/context.go @@ -186,3 +186,13 @@ func (s *Session) RemoteAddr() (addr string) { return fmt.Sprintf("%s:80", host) } + +// LocalAddr returns the local address (ip:port) of the underlying accepted connection. +// It delegates to the topmost parent context so MITM-wrapped conns work transparently. +func (c *Context) LocalAddr() net.Addr { + if c.parent == nil { + return c.conn.LocalAddr() + } + + return c.parent.ctx.LocalAddr() +}