Fix regression caused by #901: honor the beforeFilter configuration
Proper WebSocket code
Improve fix for #903