Open
Description
Bug Description
Calling c.Method("GET")
before c.Redirect("/my/route")
doesn't set the method and c.Redirect
still uses the method that the handler was originally called with.
How to Reproduce
Steps to reproduce the behavior:
- Create route
app.Put("/put", putHandler)
- Create route
app.Get("/get", getHandler)
- At the bottom of
putHandler
havec.Method("GET"); return c.Redirect("/get")
- Call
/put
with "PUT" HTTP method/verb - Notice the redirect is not
GET /get
butPUT /get
despite method being set in item 3 above
Expected Behavior
c.Method("GET")
is respected and overrides the method/verb of the original request (PUT, in this example).
Fiber Version
v2.52.6
Code Snippet (optional)
package main
import "github.com/gofiber/fiber/v2"
import "log"
func main() {
app := fiber.New()
app.Get("/get", getHandler)
app.Put("/put", putHandler)
log.Fatal(app.Listen(":3000"))
}
// This will NEVER be called
func getHandler(c *fiber.Ctx) error {
c.SendString("")
}
func putHandler(c *fiber.Ctx) error {
log.Debugf("got here and method it PUT: %v", c.Method())
c.Method("GET")
log.Debugf("now the method is set to GET: %v", c.Method())
// This results in a "PUT /get" request instead of "GET /get"
c.Redirect("/get")
}
Checklist:
- I agree to follow Fiber's Code of Conduct.
- I have checked for existing issues that describe my problem prior to opening this one.
- I understand that improperly formatted bug reports may be closed without explanation.