update Subscribe/Unsubscribe handlers in ServerOpts (#231)

## Background

Since the Server has a map of ServersSessions->subscriptions, and takes
care of routing ResourceUpdate messages to ServerSessions, I think the
decision was made to leave *ServerSession out of the
SubscribeHandler/UnsubscribeHandler signatures. However, resource
subscriptions are not specific to the a particular client and this
information is kept private in the Session today.

## Proposal

Align the Subscribe/Unsubscribe handlers with the other two handlers
that are client specific (ProgressNotificationHandler, and
RootListChangeHanlder), and include *ServerSession in the signature.

It comes in practice because because a gateway server that needs to
forward subscriptions still needs this information. The routing logic in
Server is convenient and means that most servers won't need to know
which ServerSessions are subscribed. But I think there are still use
cases where the user will need to know.
This commit is contained in:
Jim Clark 2025-08-04 11:46:49 -07:00 • committed by GitHub
commit cb17593a5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -776,9 +776,9 @@ If a server author wants to support resource subscriptions, they must provide ha
type ServerOptions struct {
...
// Function called when a client session subscribes to a resource.
SubscribeHandler func(context.Context, *SubscribeParams) error
SubscribeHandler func(context.Context, ss *ServerSession, *SubscribeParams) error
// Function called when a client session unsubscribes from a resource.
UnsubscribeHandler func(context.Context, *UnsubscribeParams) error
UnsubscribeHandler func(context.Context, ss *ServerSession, *UnsubscribeParams) error
}
```