File: client75.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 (39 lines) | stat: -rw-r--r-- 1,016 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
33
34
35
36
37
38
39
# frozen_string_literal: true

module WebSocket
  module Handshake
    module Handler
      class Client75 < Client
        # @see WebSocket::Handshake::Base#valid?
        def valid?
          super && verify_protocol
        end

        private

        # @see WebSocket::Handshake::Handler::Base#handshake_keys
        def handshake_keys
          keys = [
            %w[Upgrade WebSocket],
            %w[Connection Upgrade]
          ]
          host = @handshake.host
          host += ":#{@handshake.port}" if @handshake.port
          keys << ['Host', host]
          keys << ['Origin', @handshake.origin] if @handshake.origin
          keys << ['WebSocket-Protocol', @handshake.protocols.first] if @handshake.protocols.any?
          keys += super
          keys
        end

        def supported_protocols
          Array(@handshake.protocols.first)
        end

        def provided_protocols
          Array(@handshake.headers['websocket-protocol'].to_s.strip)
        end
      end
    end
  end
end