class Async::WebSocket::UpgradeResponse

The response from the server back to the client for negotiating HTTP/1.x WebSockets.

Public Class Methods

new(request, headers = nil, protocol: nil, &block) click to toggle source
Calls superclass method
# File lib/async/websocket/upgrade_response.rb, line 33
def initialize(request, headers = nil, protocol: nil, &block)
        headers = ::Protocol::HTTP::Headers[headers]
        
        if accept_nounce = request.headers[SEC_WEBSOCKET_KEY]&.first
                headers.add(SEC_WEBSOCKET_ACCEPT, Nounce.accept_digest(accept_nounce))
                status = 101
        else
                status = 400
        end
        
        if protocol
                headers.add(SEC_WEBSOCKET_PROTOCOL, protocol)
        end
        
        body = Async::HTTP::Body::Hijack.wrap(request, &block)
        super(request.version, status, headers, body, PROTOCOL)
end