igrigorik/em-websocket — pull request #101 by gorlowski (2013-06-11 18:45:43+00:00)
Title: initial work on onhandshake event (useful for authorization)

I don't think this is ready to pull as-is. Martyn mentioned that the rack dependency adds too much overhead. I agree that having it is probably unnecessary. If you want to allow users to send HTTP error codes in the handshake, the first step would be to identify which ones should be supported (403, 404, ... maybe LATER support 30x for redirects, but while supporting redirects would add polish, I personally don't think they are necessary).

Right now my API additions support either throwing exceptions or returning numeric HTTP error codes in onhandshake (syntactic sugar) that then get wrapped in an exception. Supporting a finite set of exceptions w/o supporting numeric error codes would simplify the code and would not require implementation of ALL possible HTTP errors (only the handful of useful ones). Users could also subclass HandshakeError with an exception that would support a compatible API (implement code() and an http_status_message() or something like that) so they could implement others as-needed. We could provide an example of a generic extension of HandshakeError that could use Rack to translate codes-to-messages and thereby support many more codes without having to add this exception class (and the rack dependency) to em-websocket itself.

Anyway, I'm open to suggestions for possible improvements to the API that should happen prior to pull.