bricks icon indicating copy to clipboard operation
bricks copied to clipboard

Add websocket instrumentation middleware

Open nicmue opened this issue 6 years ago • 0 comments

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.

nicmue avatar Nov 21 '19 08:11 nicmue