module Async::WebSocket::Adapters::HTTP
Public Class Methods
open(request, headers: [], protocols: [], handler: Connection, **options) { |connection| ... }
click to toggle source
# File lib/async/websocket/adapters/http.rb, line 36 def self.open(request, headers: [], protocols: [], handler: Connection, **options, &block) if Array(request.protocol).include?(PROTOCOL) # Select websocket sub-protocol: if requested_protocol = request.headers[SEC_WEBSOCKET_PROTOCOL] protocol = (requested_protocol & protocols).first end response = Response.for(request, headers, protocol: protocol, **options) do |stream| # Once we get to this point, we no longer need to hold on to the response: response = nil framer = Protocol::WebSocket::Framer.new(stream) connection = handler.call(framer, protocol) yield connection connection.close unless connection.closed? end # Once we get to this point, we no longer need to hold on to the request: request = nil return response end end
websocket?(request)
click to toggle source
# File lib/async/websocket/adapters/http.rb, line 32 def self.websocket?(request) Array(request.protocol).include?(PROTOCOL) end