From d46009f80b666df2e0e61cb6925952b19335f039 Mon Sep 17 00:00:00 2001 From: Paul Lorenz Date: Thu, 14 Nov 2024 11:37:11 -0500 Subject: [PATCH] Allow getting listener headers from a func --- classic_listener.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/classic_listener.go b/classic_listener.go index c3eda0e..e9f6643 100644 --- a/classic_listener.go +++ b/classic_listener.go @@ -40,6 +40,7 @@ type classicListener struct { connectOptions ConnectOptions tcfg transport.Configuration headers map[int32][]byte + headersF func() map[int32][]byte closed atomic.Bool listenerPool goroutines.Pool messageStrategy MessageStrategy @@ -55,6 +56,7 @@ func DefaultListenerConfig() ListenerConfig { type ListenerConfig struct { ConnectOptions Headers map[int32][]byte + HeadersF func() map[int32][]byte TransportConfig transport.Configuration PoolConfigurator func(config *goroutines.PoolConfig) ConnectionHandlers []ConnectionHandler @@ -105,6 +107,7 @@ func newClassicListener(identity *identity.TokenId, endpoint transport.Address, connectOptions: config.ConnectOptions, tcfg: config.TransportConfig, headers: config.Headers, + headersF: config.HeadersF, closed: atomic.Bool{}, listenerPool: pool, messageStrategy: config.MessageStrategy, @@ -260,6 +263,12 @@ func (self *classicListener) ackHello(impl classicUnderlay, request *Message, su response.Headers[key] = val } + if self.headersF != nil { + for key, val := range self.headersF() { + response.Headers[key] = val + } + } + response.PutStringHeader(ConnectionIdHeader, impl.ConnectionId()) if self.identity != nil { response.PutStringHeader(IdHeader, self.identity.Token)