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

Infinite redirect with Prefix in StaticOptions #201

Closed
mattdavis90 opened this issue May 29, 2020 · 2 comments · Fixed by #202
Closed

Infinite redirect with Prefix in StaticOptions #201

mattdavis90 opened this issue May 29, 2020 · 2 comments · Fixed by #202
Labels

Comments

@mattdavis90
Copy link

It looks as though #199 introduced a bug causing an infinite redirect when using StaticOptions.Prefix. This issue is around path.Clean and passing in ctx.req.URL.Path. I think this should be checked against opt.Prefix rather than "/" but this requires a special case when opt.Prefix == "" which is the fault.

Minimal example:

package main

import (
        "gopkg.in/macaron.v1"
        "net/http"
)

func main() {
        m := macaron.New()
        m.Use(macaron.Static("public", macaron.StaticOptions{
                Prefix: "/public",
        }))
        srv := &http.Server{
                Addr:    "0.0.0.0:8000",
                Handler: m,
        }
        srv.ListenAndServe()
}

Put an index.html in the public directory and navigate to http://127.0.0.1:8000/public you should get served the index.html but instead will get an infinite redirect to /public/.

@mattdavis90
Copy link
Author

I think changing line 153 in static.go to the following works.

if !strings.HasSuffix(redirPath, opt.Prefix) {

@humaidq
Copy link
Contributor

humaidq commented May 29, 2020

I think changing line 153 in static.go to the following works.

if !strings.HasSuffix(redirPath, opt.Prefix) {

This breaks other tests, I have tried other variations with similar results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

3 participants