Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mime type for HTML files and support index.html #109

Merged
merged 1 commit into from
May 22, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/guard/livereload/websocket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def dispatch(data)
parser << data
# prepend with '.' to make request url usable as a file path
request_path = '.' + URI.parse(parser.request_url).path
request_path += '/index.html' if File.directory? request_path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be request_path += './index.html' here? (a dot is prepend the line before)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say, there is a file foo/index.html and a request for /foo.
The first request_path line makes it ./foo, i.e. a local relative file path.
The second request_path line then makes it ./foo/index.html. With the line from your question it would be foo./index.html which does not exist.
The current version also works with the request /foo/ (resulting in ./foo//index.html, which still works) and / (resulting in ./index.html)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok great, gotcha!

if parser.http_method != 'GET' || parser.upgrade?
super #pass the request to websocket
elsif request_path == './livereload.js'
Expand All @@ -33,7 +34,8 @@ def _serve_file(path)
end

def _content_type(path)
case File.extname(path)
case File.extname(path).downcase
when '.html', '.htm' then 'text/html'
when '.css' then 'text/css'
when '.js' then 'application/ecmascript'
when '.gif' then 'image/gif'
Expand Down