class WebSocket::Handshake::Base
@abstract Subclass and override to implement custom handshakes
Constants
- HEADER
Attributes
Public Class Methods
Initialize new WebSocket Handshake and set it's state to :new
# File lib/websocket/handshake/base.rb, line 14 def initialize(args = {}) args.each do |k, v| value = begin v.dup rescue TypeError v end instance_variable_set("@#{k}", value) end @state = :new @handler = nil @data = String.new('') @headers ||= {} @protocols ||= [] end
Public Instance Methods
@abstract Add data to handshake
# File lib/websocket/handshake/base.rb, line 33 def <<(data) @data << data end
Is parsing of data finished? @return [Boolena] True if request was completely parsed or error occured. False otherwise
# File lib/websocket/handshake/base.rb, line 46 def finished? @state == :finished || @state == :error end
Data left from parsing. Sometimes data that doesn't belong to handshake are added - use this method to retrieve them. @return [String] String if some data are available. Nil otherwise
# File lib/websocket/handshake/base.rb, line 64 def leftovers (@leftovers.to_s.split("\n", reserved_leftover_lines + 1)[reserved_leftover_lines] || '').strip end
@abstract Should send data after parsing is finished?
# File lib/websocket/handshake/base.rb, line 58 def should_respond? raise NotImplementedError end
Return textual representation of handshake request or response @return [String] text of response
# File lib/websocket/handshake/base.rb, line 39 def to_s @handler ? @handler.to_s : '' end
URI of request. @return [String] Full URI with protocol @example
@handshake.uri #=> "ws://example.com/path?query=true"
# File lib/websocket/handshake/base.rb, line 72 def uri uri = String.new(secure ? 'wss://' : 'ws://') uri << host uri << ":#{port}" if port uri << path uri << "?#{query}" if query uri end
Is parsed data valid? @return [Boolean] False if some errors occured. Reason for error could be found in error method
# File lib/websocket/handshake/base.rb, line 52 def valid? finished? && @error.nil? && @handler && @handler.valid? end