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

Proposal - Let WebSocketProxy use an "event/state observer" callback #22

Open
janmiderback opened this issue May 25, 2018 · 0 comments
Open

Comments

@janmiderback
Copy link

Motivation

  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant