File: server75.rb

package info (click to toggle)
ruby-websocket 1.2.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 412 kB
  • sloc: ruby: 2,667; makefile: 4
file content (40 lines) | stat: -rw-r--r-- 1,094 bytes parent folder | download | duplicates (3)
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
40
# frozen_string_literal: true

module WebSocket
  module Handshake
    module Handler
      class Server75 < Server
        private

        def headers
          {
            origin: 'WebSocket-Origin',
            location: 'WebSocket-Location',
            protocol: 'WebSocket-Protocol'
          }.freeze
        end

        # @see WebSocket::Handshake::Handler::Base#header_line
        def header_line
          'HTTP/1.1 101 Web Socket Protocol Handshake'
        end

        # @see WebSocket::Handshake::Handler::Base#handshake_keys
        def handshake_keys
          [
            %w[Upgrade WebSocket],
            %w[Connection Upgrade],
            [headers[:origin], @handshake.headers['origin']],
            [headers[:location], @handshake.uri]
          ] + protocol
        end

        def protocol
          return [] unless @handshake.headers.key?(headers[:protocol].downcase)
          proto = @handshake.headers[headers[:protocol].downcase]
          [[headers[:protocol], @handshake.protocols.include?(proto) ? proto : nil]]
        end
      end
    end
  end
end