bricks
bricks copied to clipboard
Add websocket instrumentation middleware
If the server wants to handle websockets, the current http.Router() middlewares prohibit this by not forwading the net/http.Hijacker interface. As discussed with @threez we propose to implement an own middleware for http.Handler that should be later upgraded to websockets:
func Websocket(h http.Handler) http.Handler {
return func (w http.ResponseWriter, r *http.Request) {
// wrap writer to catch WriteHeader calls etc...
// check if http.Hijacker is implemented
// initialize possible metric observers for websockets etc.
h.ServeHTTP(w, r)
// error if Hijack was not called
}
}
With this extra middleware it is possible to control only websockets/hijacked connections are used on a specific http.Handler and net.Conn based metrics can be observed.