Skip to content

Redirect from POST ends in 404, even if the endpoint exists #444

Closed
@tscolari

Description

@tscolari

I've made a sample code to explain what's happening:

package main

import (
    "net/http"

    "github.com/gin-gonic/gin"
)

func main() {
    r := gin.Default()
    r.RedirectTrailingSlash = true
    r.RedirectFixedPath = true

    r.GET("/login", func(c *gin.Context) {
        form := "<form method='POST' action='/login/do'><input type='submit' /></form>"
        c.Header("Content-Type", "text/html")
        c.String(http.StatusOK, form)
    })

    r.POST("/login/do", func(c *gin.Context) {
        c.Redirect(http.StatusTemporaryRedirect, "/welcome")
    })

    r.GET("/welcome", func(c *gin.Context) {
        c.String(http.StatusOK, "Welcome")
    })

    r.Run(":8888")
}

When it tries to redirect from a POST to /login/do to /welcome the result is 404 (404 page not found).
But if I try to go directly to /welcome everything works fine.

Am I doing something wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions