Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve checks in stream? for http1 #58

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Juan Antonio Martín Lucas <[email protected]>
Aurora Nockert <[email protected]>
Thomas Morgan <[email protected]>
7 changes: 4 additions & 3 deletions lib/async/websocket/upgrade_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class UpgradeRequest < ::Protocol::HTTP::Request
include ::Protocol::WebSocket::Headers

class Wrapper
def initialize(response)
def initialize(response, verified:)
@response = response
@stream = nil
@verified = verified
end

def close
Expand All @@ -32,7 +33,7 @@ def close
attr_accessor :response

def stream?
@response.status == 101
@response.status == 101 && @verified
end

def status
Expand Down Expand Up @@ -74,7 +75,7 @@ def call(connection)
end
end

return Wrapper.new(response)
return Wrapper.new(response, verified: !!accept_digest)
end
end
end
Expand Down
28 changes: 28 additions & 0 deletions test/async/websocket/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,34 @@
with 'http/1' do
let(:protocol) {Async::HTTP::Protocol::HTTP1}
it_behaves_like ClientExamples

with 'invalid sec-websocket-accept header' do
let(:app) do
Protocol::HTTP::Middleware.for do |request|
Protocol::HTTP::Response[101, {'sec-websocket-accept'=>'wrong-digest'}, []]
end
end

it 'raises an error' do
expect do
Async::WebSocket::Client.connect(client_endpoint) {}
end.to raise_exception(Async::WebSocket::ProtocolError, message: be =~ /Invalid accept digest/)
end
end

with 'missing sec-websocket-accept header' do
let(:app) do
Protocol::HTTP::Middleware.for do |request|
Protocol::HTTP::Response[101, {}, []]
end
end

it 'raises an error' do
expect do
Async::WebSocket::Client.connect(client_endpoint) {}
end.to raise_exception(Async::WebSocket::ProtocolError, message: be =~ /Failed to negotiate connection/)
end
end
end

with 'http/2' do
Expand Down
Loading