diff --git a/lib/async/websocket/client.rb b/lib/async/websocket/client.rb index e21339a..4b7b584 100644 --- a/lib/async/websocket/client.rb +++ b/lib/async/websocket/client.rb @@ -90,14 +90,14 @@ def close end end - def connect(authority, path, headers: nil, handler: Connection, extensions: ::Protocol::WebSocket::Extensions::Client.default, **options, &block) + def connect(authority, path, scheme: @delegate.scheme, headers: nil, handler: Connection, extensions: ::Protocol::WebSocket::Extensions::Client.default, **options, &block) headers = ::Protocol::HTTP::Headers[headers] extensions&.offer do |extension| headers.add(SEC_WEBSOCKET_EXTENSIONS, extension.join("; ")) end - request = Request.new(nil, authority, path, headers, **options) + request = Request.new(scheme, authority, path, headers, **options) pool = @delegate.pool connection = pool.acquire diff --git a/test/async/websocket/client.rb b/test/async/websocket/client.rb index 663be6b..4a0efde 100644 --- a/test/async/websocket/client.rb +++ b/test/async/websocket/client.rb @@ -5,6 +5,7 @@ # Copyright, 2023, by Thomas Morgan. require 'async/websocket/client' +require 'async/websocket/adapters/http' require 'sus/fixtures/async/http/server_context' @@ -90,6 +91,30 @@ end end + with '#connect' do + let(:app) do + Protocol::HTTP::Middleware.for do |request| + Async::WebSocket::Adapters::HTTP.open(request) do |connection| + connection.send_text("authority: #{request.authority}") + connection.send_text("path: #{request.path}") + connection.send_text("protocol: #{Array(request.protocol).inspect}") + connection.send_text("scheme: #{request.scheme}") + connection.close + end or Protocol::HTTP::Response[404, {}, []] + end + end + + it "fully populates the request" do + connection = Async::WebSocket::Client.connect(client_endpoint) + expect(connection.read.to_str).to be =~ /authority: localhost:\d+/ + expect(connection.read.to_str).to be == 'path: /' + expect(connection.read.to_str).to be == 'protocol: ["websocket"]' + expect(connection.read.to_str).to be == 'scheme: http' + ensure + connection&.close + end + end + with 'missing support for websockets' do let(:app) do Protocol::HTTP::Middleware.for do |request|