Class: Funnel::Routing::Router
- Inherits:
-
WebSocket::Connection
- Object
- EM::Connection
- WebSocket::Connection
- Funnel::Routing::Router
- Defined in:
- lib/funnel/routing/router.rb
Instance Attribute Summary
Attributes inherited from WebSocket::Connection
Instance Method Summary collapse
-
#accept_connection ⇒ Object
TODO: add WebSocket-Protocol.
-
#defer_connection ⇒ Object
change the handler from this instance, to a new instance of the type defined by the routing map.
-
#receive_data(data) ⇒ Object
parse headers, validate headers, accept connection, and change the default handler.
- #requested_protocol ⇒ Object
-
#valid_connection? ⇒ Boolean
is this a websocket connection?.
- #valid_route? ⇒ Boolean
Methods inherited from WebSocket::Connection
#cookies, #host, #on_data, #on_disconnect, #on_ready, #origin, #path, #post_init, #protocol, #send_message, #unbind
Instance Method Details
#accept_connection ⇒ Object
TODO: add WebSocket-Protocol
27 28 29 30 31 32 33 34 35 |
# File 'lib/funnel/routing/router.rb', line 27 def accept_connection response = "HTTP/1.1 101 Web Socket Protocol Handshake\r\n" response << "Upgrade: WebSocket\r\n" response << "Connection: Upgrade\r\n" response << "WebSocket-Origin: #{origin}\r\n" response << "WebSocket-Location: ws://#{host}#{path}\r\n\r\n" send_data response end |
#defer_connection ⇒ Object
change the handler from this instance, to a new instance of the type defined by the routing map
39 40 41 42 |
# File 'lib/funnel/routing/router.rb', line 39 def defer_connection puts "got this far" EM.instance_variable_get("@conns")[@signature] = Routes.get_handler(path).send(:new, @signature) end |
#receive_data(data) ⇒ Object
parse headers, validate headers, accept connection, and change the default handler
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/funnel/routing/router.rb', line 8 def receive_data data @headers = WebSocket::Headers.parse(data) if valid_connection? && valid_route? accept_connection defer_connection else close_connection end end |
#requested_protocol ⇒ Object
48 49 50 |
# File 'lib/funnel/routing/router.rb', line 48 def requested_protocol @header[:websocket_protocol] || :default end |
#valid_connection? ⇒ Boolean
is this a websocket connection?
22 23 24 |
# File 'lib/funnel/routing/router.rb', line 22 def valid_connection? @headers[:connection] =~ /upgrade/i && @headers[:upgrade] =~ /websocket/i end |
#valid_route? ⇒ Boolean
44 45 46 |
# File 'lib/funnel/routing/router.rb', line 44 def valid_route? true end |