Echo: Inability to redirect from a POST to a GET

Created on 7 Oct 2015  路  3Comments  路  Source: labstack/echo

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.

Most helpful comment

Makes sense actually. Looks like this works if using http.StatusFound - Kinda unexpected behavior, but not the fault of Go.

Thanks!

All 3 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

linux-support picture linux-support  路  3Comments

montanaflynn picture montanaflynn  路  3Comments

younisshah picture younisshah  路  4Comments

alexzorin picture alexzorin  路  3Comments

dre1080 picture dre1080  路  4Comments