fiber
fiber copied to clipboard
🐛 [Bug]: c.Download Failure
Bug Description
c.Download Failure
How to Reproduce
Use the following two methods at the same time
app.Use("/", filesystem.New(filesystem.Config{
Root: http.FS(web.Dist),
Browse: true,
Index: "index.html",
NotFoundFile: "404.html",
PathPrefix: "/dist",
MaxAge: 3600,
}))
app.Get("/download", func(c *fiber.Ctx) error {
return c.Download("./test.txt", "test.txt")
})
Expected Behavior
/download
Invalid request
Fiber Version
v2.39.0
Code Snippet (optional)
No response
Checklist:
- [X] I agree to follow Fiber's Code of Conduct.
- [X] I have checked for existing issues that describe my problem prior to opening this one.
- [X] I understand that improperly formatted bug reports may be closed without explanation.
This problem has been solved. Just adjust the order to
app.Get("/download", func(c *fiber.Ctx) error {
return c.Download("./test.txt", "test.txt")
})
app.Use("/", filesystem.New(filesystem.Config{
Root: http.FS(web.Dist),
Browse: true,
Index: "index.html",
NotFoundFile: "404.html",
PathPrefix: "/dist",
MaxAge: 3600,
}))
Now I'm not sure if it's a bug
Let me see.
@li-jin-gou can we close the issue ?
I'll try it today.💕
and the day went on and on.. it seemingly never ended and our heroes were trapped in the day forever.
@li-jin-gou did you find time to check ?
@ReneWerner87 it seems that fiber could not guarantee that the execution order of middleware and route in treeStack
.(the execution order is relative to registration order e.g. this issue) I think the middleware might be executed before the routes ?( not sure :((( )
fiber can guarantee the order in version 2 we use the same logic as express and process the routes in the order in which they are registered
for more info please look here https://docs.gofiber.io/guide/routing#paths
https://github.com/gofiber/fiber/issues/1952#issuecomment-1169568116 https://github.com/gofiber/fiber/issues/1090#issuecomment-751335790 https://github.com/gofiber/fiber/issues/1088#issuecomment-750476089 https://github.com/gofiber/fiber/issues/1469#issuecomment-892930189
fiber can guarantee the order in version 2 we use the same logic as express and process the routes in the order in which they are registered
for more info please look here https://docs.gofiber.io/guide/routing#paths
#1952 (comment) #1090 (comment) #1088 (comment) #1469 (comment)
thanks for reply! these help me a lot
I'm tryed too
Since this issue seems to just be caused by the order of route execution, it seems like it can be closed.
@qmdx Can we close this?