mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-18 16:55:37 +03:00
caddy: Re-invoke listener middlewares on reloads and upgrades
This commit is contained in:
parent
1f8d1df4ec
commit
4f5df39bdd
2 changed files with 21 additions and 4 deletions
7
caddy.go
7
caddy.go
|
@ -388,6 +388,11 @@ type GracefulServer interface {
|
||||||
// address; you must store the address the
|
// address; you must store the address the
|
||||||
// server is to serve on some other way.
|
// server is to serve on some other way.
|
||||||
Address() string
|
Address() string
|
||||||
|
|
||||||
|
// WrapListener wraps a listener with the
|
||||||
|
// listener middlewares configured for this
|
||||||
|
// server, if any.
|
||||||
|
WrapListener(net.Listener) net.Listener
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listener is a net.Listener with an underlying file descriptor.
|
// Listener is a net.Listener with an underlying file descriptor.
|
||||||
|
@ -744,6 +749,7 @@ func startServers(serverList []Server, inst *Instance, restartFds map[string]res
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ln = gs.WrapListener(ln)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -782,6 +788,7 @@ func startServers(serverList []Server, inst *Instance, restartFds map[string]res
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ln = gs.WrapListener(ln)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -274,16 +274,26 @@ func (s *Server) Listen() (net.Listener, error) {
|
||||||
ln = tcpKeepAliveListener{TCPListener: tcpLn}
|
ln = tcpKeepAliveListener{TCPListener: tcpLn}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cln := s.WrapListener(ln)
|
||||||
|
|
||||||
|
// Very important to return a concrete caddy.Listener
|
||||||
|
// implementation for graceful restarts.
|
||||||
|
return cln.(caddy.Listener), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// WrapListener wraps ln in the listener middlewares configured
|
||||||
|
// for this server.
|
||||||
|
func (s *Server) WrapListener(ln net.Listener) net.Listener {
|
||||||
|
if ln == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
cln := ln.(caddy.Listener)
|
cln := ln.(caddy.Listener)
|
||||||
for _, site := range s.sites {
|
for _, site := range s.sites {
|
||||||
for _, m := range site.listenerMiddleware {
|
for _, m := range site.listenerMiddleware {
|
||||||
cln = m(cln)
|
cln = m(cln)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return cln
|
||||||
// Very important to return a concrete caddy.Listener
|
|
||||||
// implementation for graceful restarts.
|
|
||||||
return cln.(caddy.Listener), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListenPacket creates udp connection for QUIC if it is enabled,
|
// ListenPacket creates udp connection for QUIC if it is enabled,
|
||||||
|
|
Loading…
Reference in a new issue