square/SocketRocket — pull request #203 by danielalves (2014-10-06 01:38:51+00:00)
Title: Keeping original NSURLRequest object HTTPMethod and HTTPBody

Not stripping the original `NSURLRequest` object `HTTPBody` and keeping its `HTTPMethod` gives us the possibility of doing some checks on the server before establishing the websocket. For example, you could have something like this using `ruby`, `sinatra` and `sinatra-websockets`:

```ruby
post '/web-socket-url' do
if !request.websocket?
return status 404
end

# Without HTTP method post and body data we can't do this in a proper way... Only if we sent
# this parameter in the query string, what's not good for sensible data
user_access_token = params[:user_token]

if !( is_valid_token? user_access_token )
return status 404
end

# Only now we start handling the websocket
request.websocket do |ws|

ws.onopen do
# ...
end

ws.onmessage do |message|
# ...
end

ws.onclose do
# ...
end
end
end
```