fiber icon indicating copy to clipboard operation
fiber copied to clipboard

🐛 [Bug]: c.Download Failure

Open qmdx opened this issue 2 years ago • 12 comments

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.

qmdx avatar Nov 16 '22 08:11 qmdx

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

qmdx avatar Nov 16 '22 11:11 qmdx

Let me see.

li-jin-gou avatar Nov 19 '22 03:11 li-jin-gou

@li-jin-gou can we close the issue ?

ReneWerner87 avatar Jan 09 '23 07:01 ReneWerner87

I'll try it today.💕

li-jin-gou avatar Jan 09 '23 07:01 li-jin-gou

and the day went on and on.. it seemingly never ended and our heroes were trapped in the day forever.

G2G2G2G avatar Mar 17 '23 08:03 G2G2G2G

@li-jin-gou did you find time to check ?

ReneWerner87 avatar Mar 17 '23 09:03 ReneWerner87

@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 :((( )

Rorke76753 avatar Mar 20 '23 14:03 Rorke76753

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

ReneWerner87 avatar Mar 20 '23 14:03 ReneWerner87

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

Rorke76753 avatar Mar 20 '23 16:03 Rorke76753

I'm tryed too

JacobYarn avatar Jul 12 '23 02:07 JacobYarn

Since this issue seems to just be caused by the order of route execution, it seems like it can be closed.

nickajacks1 avatar Dec 28 '23 23:12 nickajacks1

@qmdx Can we close this?

gaby avatar Dec 28 '23 23:12 gaby