Skip to content

Commit

Permalink
Merge pull request #99 from dalyons/master
Browse files Browse the repository at this point in the history
remove dependency on Http::Parser#request_path
  • Loading branch information
thibaudgg committed Jan 16, 2014
2 parents 9f8a6a7 + edc6db1 commit 5adca8f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/guard/livereload/websocket.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'eventmachine'
require 'em-websocket'
require 'http/parser'
require 'uri'

module Guard
class LiveReload
Expand All @@ -9,12 +10,13 @@ class WebSocket < EventMachine::WebSocket::Connection
def dispatch(data)
parser = Http::Parser.new
parser << data
request_path = URI.parse(parser.request_url).path
if parser.http_method != 'GET' || parser.upgrade?
super #pass the request to websocket
elsif parser.request_path == '/livereload.js'
elsif 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
elsif File.exist?(request_path[1..-1])
_serve_file(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
Expand Down

0 comments on commit 5adca8f

Please sign in to comment.