66 "errors"
77 "unicode"
88
9+ "github.com/centrifugal/centrifugo/v5/internal/clientcontext"
910 "github.com/centrifugal/centrifugo/v5/internal/clientstorage"
1011 "github.com/centrifugal/centrifugo/v5/internal/config"
1112 "github.com/centrifugal/centrifugo/v5/internal/configtypes"
@@ -31,7 +32,7 @@ type ProxyMap struct {
3132 SubscribeStreamProxies map [string ]* proxy.SubscribeStreamProxy
3233}
3334
34- // Handler .. .
35+ // Handler for client connections .
3536type Handler struct {
3637 node * centrifuge.Node
3738 cfgContainer * config.Container
@@ -41,7 +42,7 @@ type Handler struct {
4142 rpcExtension map [string ]RPCExtensionFunc
4243}
4344
44- // NewHandler .. .
45+ // NewHandler creates new Handler .
4546func NewHandler (
4647 node * centrifuge.Node ,
4748 cfgContainer * config.Container ,
@@ -337,7 +338,7 @@ func (h *Handler) OnClientConnecting(
337338
338339 processClientChannels = true
339340 } else if connectProxyHandler != nil {
340- connectReply , _ , err := connectProxyHandler (ctx , e )
341+ connectReply , _ , err := connectProxyHandler (clientcontext . SetEmulatedHeadersToContext ( ctx , e . Headers ) , e )
341342 if err != nil {
342343 return centrifuge.ConnectReply {}, err
343344 }
@@ -414,7 +415,7 @@ func (h *Handler) OnClientConnecting(
414415 return centrifuge.ConnectReply {}, centrifuge .ErrorInternal
415416 }
416417
417- if ! isPrivate && chOpts .SubscribeProxyName == "" && validChannelName {
418+ if ! isPrivate && ! chOpts .SubscribeProxyEnabled && validChannelName {
418419 if isUserLimited && chOpts .UserLimitedChannels && (userID != "" && h .cfgContainer .UserAllowed (ch , userID )) {
419420 channelOk = true
420421 } else if chOpts .SubscribeForClient && (userID != "" || chOpts .SubscribeForAnonymous ) {
@@ -450,6 +451,13 @@ func (h *Handler) OnClientConnecting(
450451 Data : data ,
451452 ClientSideRefresh : ! refreshProxyEnabled ,
452453 }
454+ if len (e .Headers ) > 0 {
455+ if newCtx != nil {
456+ newCtx = clientcontext .SetEmulatedHeadersToContext (newCtx , e .Headers )
457+ } else {
458+ newCtx = clientcontext .SetEmulatedHeadersToContext (ctx , e .Headers )
459+ }
460+ }
453461 if newCtx != nil {
454462 finalReply .Context = newCtx
455463 }
@@ -695,17 +703,17 @@ func (h *Handler) OnSubscribe(c Client, e centrifuge.SubscribeEvent, subscribePr
695703 } else if isUserLimitedChannel && h .cfgContainer .UserAllowed (e .Channel , c .UserID ()) {
696704 allowed = true
697705 options .Source = subsource .UserLimited
698- } else if (chOpts .SubscribeProxyName != "" ) && ! isUserLimitedChannel {
706+ } else if (chOpts .SubscribeProxyEnabled ) && ! isUserLimitedChannel {
699707 if subscribeProxyHandler == nil {
700708 h .node .Log (centrifuge .NewLogEntry (centrifuge .LogLevelInfo , "subscribe proxy not enabled" , map [string ]any {"channel" : e .Channel , "user" : c .UserID (), "client" : c .ID ()}))
701709 return centrifuge.SubscribeReply {}, SubscribeExtra {}, centrifuge .ErrorNotAvailable
702710 }
703711 r , _ , err := subscribeProxyHandler (c , e , chOpts , getPerCallData (c ))
704- if chOpts .SubRefreshProxyName != "" {
712+ if chOpts .SubRefreshProxyEnabled {
705713 r .ClientSideRefresh = false
706714 }
707715 return r , SubscribeExtra {}, err
708- } else if (chOpts .SubscribeStreamProxyName != "" ) && ! isUserLimitedChannel {
716+ } else if (chOpts .SubscribeStreamProxyEnabled ) && ! isUserLimitedChannel {
709717 if subscribeStreamHandlerFunc == nil {
710718 h .node .Log (centrifuge .NewLogEntry (centrifuge .LogLevelInfo , "stream proxy not enabled" , map [string ]any {"channel" : e .Channel , "user" : c .UserID (), "client" : c .ID ()}))
711719 return centrifuge.SubscribeReply {}, SubscribeExtra {}, centrifuge .ErrorNotAvailable
@@ -717,7 +725,7 @@ func (h *Handler) OnSubscribe(c Client, e centrifuge.SubscribeEvent, subscribePr
717725 storage ["stream_publisher_" + e .Channel ] = publishFunc
718726 release (storage )
719727 }
720- if chOpts .SubRefreshProxyName != "" {
728+ if chOpts .SubRefreshProxyEnabled {
721729 r .ClientSideRefresh = false
722730 }
723731 return r , SubscribeExtra {}, err
@@ -748,7 +756,7 @@ func (h *Handler) OnSubscribe(c Client, e centrifuge.SubscribeEvent, subscribePr
748756
749757 return centrifuge.SubscribeReply {
750758 Options : options ,
751- ClientSideRefresh : chOpts .SubRefreshProxyName == "" ,
759+ ClientSideRefresh : ! chOpts .SubRefreshProxyEnabled ,
752760 }, SubscribeExtra {}, nil
753761}
754762
@@ -771,13 +779,13 @@ func (h *Handler) OnPublish(c Client, e centrifuge.PublishEvent, publishProxyHan
771779
772780 var allowed bool
773781
774- if chOpts .PublishProxyName != "" {
782+ if chOpts .PublishProxyEnabled {
775783 if publishProxyHandler == nil {
776784 h .node .Log (centrifuge .NewLogEntry (centrifuge .LogLevelInfo , "publish proxy not enabled" , map [string ]any {"channel" : e .Channel , "user" : c .UserID (), "client" : c .ID ()}))
777785 return centrifuge.PublishReply {}, centrifuge .ErrorNotAvailable
778786 }
779787 return publishProxyHandler (c , e , chOpts , getPerCallData (c ))
780- } else if chOpts .SubscribeStreamProxyName != "" {
788+ } else if chOpts .SubscribeStreamProxyEnabled {
781789 if ! chOpts .SubscribeStreamBidirectional {
782790 return centrifuge.PublishReply {}, centrifuge .ErrorNotAvailable
783791 }
0 commit comments