-
-
Save Industrial/da1543f190161d8e30cb35b8a5809939 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rack' | |
require 'async/websocket/adapters/rack' | |
GUID = '3f35e4f2-3920-4797-9044-c4046ea4fb53' | |
def create_websocket_accept (nonce) | |
Digest::SHA1.base64digest "#{nonce}#{GUID}" | |
end | |
def get_response_headers (env) | |
request = Rack::Request.new env | |
return [ | |
['Sec-Websocket-Protocol', (request.get_header 'HTTP_SEC_WEBSOCKET_PROTOCOL')], | |
['Sec-Websocket-Version', (request.get_header 'HTTP_SEC_WEBSOCKET_VERSION')], | |
['Sec-Websocket-Accept', (create_websocket_accept request.get_header 'HTTP_SEC_WEBSOCKET_KEY')], | |
] | |
end | |
def get_response_protocols (env) | |
return ['ws'] | |
end | |
App = lambda do |env| | |
Async::WebSocket::Adapters::Rack.open(env, headers: (get_response_headers env), protocols: (get_response_protocols env)) do |connection| | |
while message = connection.read | |
pp message | |
end | |
end or [200, {}, ["Hello World"]] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment