logging middleware could hook into certain events through the WebSocket upgrade and connection
metrics middleware could housekeep times and durations of WebSocket upgrade states
Some of this is possible now, but it requires to wrap ResponseWriters and it is not granular enough.
Implementation
It could be something like:
type Event int
const (
InternalError Event = iota
BackendDialFailed
BackendDialSucceeded
UpgradeFailed
UpgradeSucceeded
Closed
ClosedAbnormalClosure
)
type WebsocketProxy struct {
...
// Observer, if non-nil is called at certain actions and states through the
// WebSocket upgrade process carried out in ServeHTTP. It provides a way for
// clients/middleware to hook in actions in these notifications.
// The Event parameter carries the event and the string parameter carries
// an informational string suitable for logging.
Observer func(Event, string)
...
}
The provided event and the Observer signature are just a suggestion.
Also, events could be notified using a channel. However, actions on the receiver side should
be short, and channel messaging could be implemented in the observer, if needed.
Motivation
Some of this is possible now, but it requires to wrap ResponseWriters and it is not granular enough.
Implementation
It could be something like:
The provided event and the
Observer
signature are just a suggestion.Also, events could be notified using a channel. However, actions on the receiver side should be short, and channel messaging could be implemented in the observer, if needed.