-
Notifications
You must be signed in to change notification settings - Fork 107
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
Fix serving public/index.html as a static file #234
Conversation
h/t @momolog for pushing on this issue and providing critical debugging feedback. |
@@ -72,7 +72,7 @@ func launchPumaDevBackgroundServerWithDefaults(t *testing.T) func() { | |||
} | |||
} | |||
|
|||
func getUrlWithHost(t *testing.T, url string, host string) string { | |||
func getURLWithHost(t *testing.T, url string, host string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
golint wants URL
not Url
@@ -0,0 +1 @@ | |||
<html><h1>index.html</h1></html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should never show up. it's included here to verify that we weren't able to look outside the public
directory.
http.ServeFile(w, req, path) | ||
return httputil.ErrHandled | ||
if ofile, err := os.Open(path); err == nil { | ||
http.ServeContent(w, req, req.URL.Path, fi.ModTime(), io.ReadSeeker(ofile)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://golang.org/pkg/net/http/#ServeFile
As another special case,
ServeFile
redirects any request wherer.URL.Path
ends in "/index.html" to the same path, without the final "index.html". To avoid such redirects either modify the path or useServeContent
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the downside with this approach is that you can't just drop an index.html
in public and go to mysite.localhost
. you have to navigate to mysite.localhost/index.html
.
but, puma-dev
never supported that anyway, given the req.URL.Path != "/"
I figure this is a good enhancement to consider when tackling #87
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine, your justification makes sense.
http.ServeFile(w, req, path) | ||
return httputil.ErrHandled | ||
if ofile, err := os.Open(path); err == nil { | ||
http.ServeContent(w, req, req.URL.Path, fi.ModTime(), io.ReadSeeker(ofile)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine, your justification makes sense.
This PR serves to illustrate behavior discussed in #140 and #87.Fixes #140 (at least the part of it that is not covered by #87)
As of 0.13,
puma-dev
does not support serving "naked" static files without bootingpuma
. It can, of course, be modified to support such behavior (see #87).The headline here is #234 (comment)
Changes
static-site
) with apublic
directory containinggreeting.txt
GET localhost/greeting.txt
is handled bypuma-dev
GET localhost/foo
is handled by rack.golint
warnings about usingUrl
instead ofURL
variable names.ServeContent
to avoid redirectingindex.html
back to/
. See No static content serving on test domain #140 (comment)