8000 Ensure h2 requests include `:scheme`. (#60) · socketry/async-websocket@c320706 · GitHub
[go: up one dir, main page]

Skip to content

Commit c320706

Browse files
authored
Ensure h2 requests include :scheme. (#60)
1 parent 6146dd1 commit c320706

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

lib/async/websocket/client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ def close
9090
end
9191
end
9292

93-
def connect(authority, path, headers: nil, handler: Connection, extensions: ::Protocol::WebSocket::Extensions::Client.default, **options, &block)
93+
def connect(authority, path, scheme: @delegate.scheme, headers: nil, handler: Connection, extensions: ::Protocol::WebSocket::Extensions::Client.default, **options, &block)
9494
headers = ::Protocol::HTTP::Headers[headers]
9595

9696
extensions&.offer do |extension|
9797
headers.add(SEC_WEBSOCKET_EXTENSIONS, extension.join("; "))
9898
end
9999

100-
request = Request.new(nil, authority, path, headers, **options)
100+
request = Request.new(scheme, authority, path, headers, **options)
101101

102102
pool = @delegate.pool
103103
connection = pool.acquire

test/async/websocket/client.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Copyright, 2023, by Thomas Morgan.
66

77
require 'async/websocket/client'
8+
require 'async/websocket/adapters/http'
89

910
require 'sus/fixtures/async/http/server_context'
1011

@@ -90,6 +91,30 @@
9091
end
9192
end
9293

94+
with '#connect' do
95+
let(:app) do
96+
Protocol::HTTP::Middleware.for do |request|
97+
Async::WebSocket::Adapters::HTTP.open(request) do |connection|
98+
connection.send_text("authority: #{request.authority}")
99+
connection.send_text("path: #{request.path}")
100+
connection.send_text("protocol: #{Array(request.protocol).inspect}")
101+
connection.send_text("scheme: #{request.scheme}")
102+
connection.close
103+
end or Protocol::HTTP::Response[404, {}, []]
104+
end
105+
end
106+
107+
it "fully populates the request" do
108+
connection = Async::WebSocket::Client.connect(client_endpoint)
109+
expect(connection.read.to_str).to be =~ /authority: localhost:\d+/
110+
expect(connection.read.to_str).to be == 'path: /'
111+
expect(connection.read.to_str).to be == 'protocol: ["websocket"]'
112+
expect(connection.read.to_str).to be == 'scheme: http'
113+
ensure
114+
connection&.close
115+
end
116+
end
117+
93118
with 'missing support for websockets' do
94119
let(:app) do
95120
Protocol::HTTP::Middleware.for do |request|

0 commit comments

Comments
 (0)
0