Skip to content
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Edge

- include invalid status code when raising handshake error

## 1.2.11

- remove unused base64 require that would cause issues in Ruby 3.4
Expand Down
6 changes: 6 additions & 0 deletions lib/websocket/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ def message
end

class InvalidStatusCode < ::WebSocket::Error::Handshake
attr_reader :invalid_status_code

def initialize(invalid_status_code)
@invalid_status_code = invalid_status_code
end

def message
:invalid_status_code
end
Expand Down
9 changes: 8 additions & 1 deletion lib/websocket/handshake/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,14 @@ def parse_first_line(line)
line_parts = line.match(FIRST_LINE)
raise WebSocket::Error::Handshake::InvalidHeader unless line_parts
status = line_parts[1]
raise WebSocket::Error::Handshake::InvalidStatusCode unless status == '101'

# The signature for the error doesn't take the message as the first
# argument, but rather the status code. So this should use the
# initializer to create the error.
#
# rubocop:disable Style/RaiseArgs
raise WebSocket::Error::Handshake::InvalidStatusCode.new(status) unless status == '101'
# rubocop:enable Style/RaiseArgs
end
end
end
Expand Down