Class: Hyla::WebSocket

Inherits:
EventMachine::WebSocket::Connection
  • Object
show all
Defined in:
lib/hyla/websocket.rb

Instance Method Summary collapse

Instance Method Details

#dispatch(data) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/hyla/websocket.rb', line 8

def dispatch(data)
  parser = Http::Parser.new
  parser << data
  if parser.http_method != 'GET' || parser.upgrade?
    super #pass the request to websocket
  elsif parser.request_path == '/livereload.js'
    _serve_file(_livereload_js_file)
  elsif File.exist?(parser.request_path[1..-1])
    _serve_file(parser.request_path[1..-1]) # Strip leading slash
  else
    send_data("HTTP/1.1 404 Not Found\r\nContent-Type: text/plain\r\nContent-Length: 13\r\n\r\n404 Not Found")
    close_connection_after_writing
  end
end