Skip to content

Commit 5adca8f

Browse files
committed
Merge pull request #99 from dalyons/master
remove dependency on Http::Parser#request_path
2 parents 9f8a6a7 + edc6db1 commit 5adca8f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/guard/livereload/websocket.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'eventmachine'
22
require 'em-websocket'
33
require 'http/parser'
4+
require 'uri'
45

56
module Guard
67
class LiveReload
@@ -9,12 +10,13 @@ class WebSocket < EventMachine::WebSocket::Connection
910
def dispatch(data)
1011
parser = Http::Parser.new
1112
parser << data
13+
request_path = URI.parse(parser.request_url).path
1214
if parser.http_method != 'GET' || parser.upgrade?
1315
super #pass the request to websocket
14-
elsif parser.request_path == '/livereload.js'
16+
elsif request_path == '/livereload.js'
1517
_serve_file(_livereload_js_file)
16-
elsif File.exist?(parser.request_path[1..-1])
17-
_serve_file(parser.request_path[1..-1]) # Strip leading slash
18+
elsif File.exist?(request_path[1..-1])
19+
_serve_file(request_path[1..-1]) # Strip leading slash
1820
else
1921
send_data("HTTP/1.1 404 Not Found\r\nContent-Type: text/plain\r\nContent-Length: 13\r\n\r\n404 Not Found")
2022
close_connection_after_writing

0 commit comments

Comments
 (0)