-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Fix Static files route not working #1723
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,15 @@ func TestEchoStatic(t *testing.T) { | |
expectHeaderLocation: "/folder/", | ||
expectBodyStartsWith: "", | ||
}, | ||
{ | ||
name: "Directory Redirect with non-root path", | ||
givenPrefix: "/static", | ||
givenRoot: "_fixture", | ||
whenURL: "/static", | ||
expectStatus: http.StatusMovedPermanently, | ||
expectHeaderLocation: "/static/", | ||
expectBodyStartsWith: "", | ||
}, | ||
{ | ||
name: "Directory with index.html", | ||
givenPrefix: "/", | ||
|
@@ -161,6 +170,40 @@ func TestEchoStatic(t *testing.T) { | |
} | ||
} | ||
|
||
func TestEchoStaticRedirectIndex(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should not run tests like that because:
|
||
assert := assert.New(t) | ||
e := New() | ||
|
||
// HandlerFunc | ||
e.Static("/static", "_fixture") | ||
|
||
errCh := make(chan error) | ||
|
||
go func() { | ||
errCh <- e.Start("127.0.0.1:1323") | ||
}() | ||
|
||
time.Sleep(200 * time.Millisecond) | ||
|
||
if resp, err := http.Get("http://127.0.0.1:1323/static"); err == nil { | ||
defer resp.Body.Close() | ||
assert.Equal(http.StatusOK, resp.StatusCode) | ||
|
||
if body, err := ioutil.ReadAll(resp.Body); err == nil { | ||
assert.Equal(true, strings.HasPrefix(string(body), "<!doctype html>")) | ||
} else { | ||
assert.Fail(err.Error()) | ||
} | ||
|
||
} else { | ||
assert.Fail(err.Error()) | ||
} | ||
|
||
if err := e.Close(); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func TestEchoFile(t *testing.T) { | ||
e := New() | ||
e.File("/walle", "_fixture/images/walle.png") | ||
|
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.
Then dealing with this method we need to consider where is is called. Is it
e.Static()
orgroup.Static()
e.Static()
is on server root level i.e.http://server/assets/cat.gif
URLsgroup.Static
is on group level which means in addition to this method prefix we have group path as prefix in url. i.e.http://server/group/assets/cat.gif
and regarding to
prefix
we should consider it ends with slash or noti.e. prefixes:
/
/assets
/assets/
now lets add two possibilities here: if group path is
/user
or/user/
what routes we will end up with?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.
something like that