Open Victoryship opened 1 year ago
func main() {
router := gin.Default()
v1 := router.Group("/api")
{
v1.Use(Middleware1(), Middleware2(), Middleware3(), Middleware4())
v1.GET("/test", FinalHandler)
}
v2 := router.Group("/router")
{
v2.GET("/index", func(c *gin.Context) {
fmt.Println("改写")
c.Request.URL.Path = "/api/test"
c.Abort()
router.HandleContext(c)
})
}
router.Run(":8080")
}
I can rewrite it like this, but I don't know why
Hi @Victoryship, as per https://jastorey.me/blog/request-rewrite-in-gin.html, your rewrite works because you're cancelling the initial context handling with c.Abort()
to make sure the response buffer is not written twice.
Thank you @YuukanOO for answering,I check the source code here to see if it should be modified that don't need abort
Description
I ran into this problem while testing implementing internal redirects
How to reproduce
Expectations
Actual result
Environment