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 41 42 43 44 45 46 47 48 49
|
# frozen_string_literal: true
module WebSocket
module Handshake
module Handler
# This class and it's descendants are included in client or server handshake in order to extend basic functionality
class Base
def initialize(handshake)
@handshake = handshake
end
# @see WebSocket::Handshake::Base#to_s
def to_s
result = [header_line]
handshake_keys.each do |key|
result << key.join(': ')
end
result << ''
result << finishing_line
result.join("\r\n")
end
def valid?
true
end
private
# Set first line of text representation according to specification.
# @return [String] First line of HTTP header
def header_line
''
end
# Set handshake headers. Provided as array because some protocol version require specific order of fields.
# @return [Array] List of headers as arrays [key, value]
def handshake_keys
[]
end
# Set data to send after headers. In most cases it will be blank data.
# @return [String] data
def finishing_line
''
end
end
end
end
end
|