Module: Async::WebSocket::Adapters::Native
- Includes:
- Protocol::WebSocket::Headers
- Defined in:
- lib/pakyow/realtime/websocket.rb
Class Method Summary collapse
- .open(request, headers: [], protocols: [], handler: Connection, **options) ⇒ Object
- .websocket?(request) ⇒ Boolean
Class Method Details
.open(request, headers: [], protocols: [], handler: Connection, **options) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/pakyow/realtime/websocket.rb', line 140 def self.open(request, headers: [], protocols: [], handler: Connection, **) if websocket?(request) && Array(request.protocol).include?(PROTOCOL) # Select websocket sub-protocol: if requested_protocol = request.headers[SEC_WEBSOCKET_PROTOCOL] protocol = (requested_protocol & protocols).first end Response.for(request, headers, protocol: protocol, **) do |stream| framer = Protocol::WebSocket::Framer.new(stream) yield handler.call(framer, protocol) end else nil end end |
.websocket?(request) ⇒ Boolean
136 137 138 |
# File 'lib/pakyow/realtime/websocket.rb', line 136 def self.websocket?(request) request.headers.include?("upgrade") end |