File: client.rb

package info (click to toggle)
ruby-websocket 1.2.9-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 464 kB
  • sloc: ruby: 2,669; makefile: 4
file content (32 lines) | stat: -rw-r--r-- 946 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

module WebSocket
  module Handshake
    module Handler
      class Client < Base
        private

        # @see WebSocket::Handshake::Handler::Base#header_line
        def header_line
          path = @handshake.path
          path += '?' + @handshake.query if @handshake.query
          "GET #{path} HTTP/1.1"
        end

        # @see WebSocket::Handshake::Handler::Base#header_handshake_keys
        def handshake_keys
          super + @handshake.headers.to_a
        end

        # Verify if received header matches with one of the sent ones
        # @return [Boolean] True if matching. False otherwise(appropriate error is set)
        def verify_protocol
          return true if supported_protocols.empty?
          protos = provided_protocols & supported_protocols
          raise WebSocket::Error::Handshake::UnsupportedProtocol if protos.empty?
          true
        end
      end
    end
  end
end