Skip to content

Commit

Permalink
ensure h2 requests include :scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
zarqman committed Sep 13, 2023
1 parent fd57e55 commit cafe8b6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/async/websocket/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions test/async/websocket/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Copyright, 2023, by Samuel Williams.

require 'async/websocket/client'
require 'async/websocket/adapters/http'

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

Expand Down Expand Up @@ -89,6 +90,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|
Expand Down

0 comments on commit cafe8b6

Please sign in to comment.