diff --git a/examples/websockets/config.ru b/examples/websockets/config.ru index 4ebaef82..1cb2e662 100644 --- a/examples/websockets/config.ru +++ b/examples/websockets/config.ru @@ -4,6 +4,10 @@ require 'async/websocket' require 'async/websocket/adapters/rack' class App + def handle_normal_request(env) + [200, {'content-type' => 'text/plain'}, ["Hello World"]] + end + def call(env) Async::WebSocket::Adapters::Rack.open(env) do |connection| message = Protocol::WebSocket::TextMessage.generate({body: "Hello World"}) @@ -12,7 +16,7 @@ class App while message = connection.read connection.write(message) end - end or [400, {}, []] + end or handle_normal_request(env) end end diff --git a/test/falcon/command/virtual.rb b/test/falcon/command/virtual.rb index dbec2e40..d768a761 100644 --- a/test/falcon/command/virtual.rb +++ b/test/falcon/command/virtual.rb @@ -117,11 +117,21 @@ def around it "can upgrade to websocket" do Sync do - Async::WebSocket::Client.connect(host_endpoint) do |connection| - message = Protocol::WebSocket::TextMessage.generate({body: "Hello World"}) + 2.times do + # Normal request: + request = Protocol::HTTP::Request.new("https", "websockets.localhost", "GET", "/index") + response = secure_client.call(request) - connection.write(message) - expect(connection.read).to be == message + expect(response).to be(:success?) + expect(response.read).to be == "Hello World" + + # WebSocket request: + Async::WebSocket::Client.connect(host_endpoint) do |connection| + message = Protocol::WebSocket::TextMessage.generate({body: "Hello World"}) + + connection.write(message) + expect(connection.read).to be == message + end end end end