Parent

Included Modules

EventMachine::WebSocket::Handshake

Resposible for creating the server handshake response

Attributes

parser[R]
protocol_version[R]

Public Class Methods

new(secure) click to toggle source

Unfortunately drafts 75 & 76 require knowledge of whether the connection is being terminated as ws/wss in order to generate the correct handshake response

# File lib/em-websocket/handshake.rb, line 15
def initialize(secure)
  @parser = Http::Parser.new
  @secure = secure

  @parser.on_headers_complete = proc { |headers|
    @headers = Hash[headers.map { |k,v| [k.downcase, v] }]
  }
end

Public Instance Methods

headers() click to toggle source

Returns the WebSocket upgrade headers as a hash.

Keys are strings, unmodified from the request.

# File lib/em-websocket/handshake.rb, line 38
def headers
  @parser.headers
end
headers_downcased() click to toggle source

The same as headers, except that the hash keys are downcased

# File lib/em-websocket/handshake.rb, line 44
def headers_downcased
  @headers
end
origin() click to toggle source

Returns the WebSocket origin header if provided

# File lib/em-websocket/handshake.rb, line 65
def origin
  @headers["origin"] || @headers["sec-websocket-origin"] || nil
end
path() click to toggle source

Returns the request path (excluding any query params)

# File lib/em-websocket/handshake.rb, line 50
def path
  @parser.request_path
end
query() click to toggle source
# File lib/em-websocket/handshake.rb, line 59
def query
  Hash[query_string.split('&').map { |c| c.split('=', 2) }]
end
query_string() click to toggle source

Returns the query params as a string foo=bar&baz=...

# File lib/em-websocket/handshake.rb, line 55
def query_string
  @parser.query_string
end
receive_data(data) click to toggle source
# File lib/em-websocket/handshake.rb, line 24
def receive_data(data)
  @parser << data

  if defined? @headers
    process(@headers, @parser.upgrade_data)
  end
rescue HTTP::Parser::Error => e
  fail(HandshakeError.new("Invalid HTTP header: #{e.message}"))
end
secure?() click to toggle source
# File lib/em-websocket/handshake.rb, line 69
def secure?
  @secure
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.