func getHandler(c *echo.Context) error {
return c.String("Hello world")
}
func postHandler(c *echo.Context) error {
return echo.Redirect(http.StatusTemporaryRedirect, "/")
}
func main() {
e := echo.New()
e.Get("/", getHandler)
e.Post("/post", postHandler)
e.Run(":8080")
}
I whipped up that example pretty quickly, so I'm not entirely sure it works PERFECT, but the case that it makes hold true. For situations where you would want to redirect from a POST to a GET (for example, POST to a login form, and then redirect them back to the index), echo.Redirect fails. The redirect actually redirects to POST / instead of the expected GET /
I found some resources regarding this in Go that were solved in 2012, but has been resolved for some time. I'm assuming this might be within echo instead of Go's HTTP layer directly.
Bump - Anyone have any thoughts on this?
I just played around with redirect codes and found the following information:
307 was introduced to allow servers to make it clear to the user agent that a method change should not be made by the client when following the Location response header.
http://stackoverflow.com/a/2068504/197473
So you in this case you should use 301 or 302?
Makes sense actually. Looks like this works if using http.StatusFound - Kinda unexpected behavior, but not the fault of Go.
Thanks!
Most helpful comment
Makes sense actually. Looks like this works if using
http.StatusFound- Kinda unexpected behavior, but not the fault of Go.Thanks!