Preserve the "dispose" method when wrapping the result handler.
Handle closed connections in response handlers.

Add a "dispose" method to response handlers to get notified when the
WebSockets connection has been interrupted.
Extracted duplicate handler code to function, removed variable.
Moved code for slice handling to functions.