Skip to content

Commit

Permalink
Merge pull request #108 from isotes/fix-crash-directory-request
Browse files Browse the repository at this point in the history
Fix crash handling a request for a directory
  • Loading branch information
thibaudgg committed May 21, 2014
2 parents e016d77 + 7247fbf commit 49c2d5b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/guard/livereload/websocket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ class WebSocket < EventMachine::WebSocket::Connection
def dispatch(data)
parser = Http::Parser.new
parser << data
request_path = URI.parse(parser.request_url).path
# prepend with '.' to make request url usable as a file path
request_path = '.' + URI.parse(parser.request_url).path
if parser.http_method != 'GET' || parser.upgrade?
super #pass the request to websocket
elsif request_path == '/livereload.js'
elsif request_path == './livereload.js'
_serve_file(_livereload_js_file)
elsif File.exist?(request_path[1..-1])
_serve_file(request_path[1..-1]) # Strip leading slash
elsif File.readable?(request_path) && !File.directory?(request_path)
_serve_file(request_path)
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 49c2d5b

Please sign in to comment.