Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow getting listener headers from a func #149

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions classic_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
Loading