is there a bug in internal redirect? it makes abort() of midware not work
Author: fengdingfeilongCreated Nov 20, 2021Updated Aug 6, 2026
Description
when i use internal redirect from url1 to url2, the midware of url2 can not abort. however if i use external redirect(http 302), it works as expected.
How to reproduce
package main
import (
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.GET("/t1", func(c *gin.Context) {
c.Request.URL.Path = "/t2"
r.HandleContext(c)
// c.Redirect(302, "/t2")
})
r.Use(func(c *gin.Context) {
c.AbortWithStatusJSON(200, gin.H{"result": "mid"})
})
r.GET("/t2", func(c *gin.Context) {
c.JSON(200, gin.H{"result": "t2"})
})
r.Run(":8090")
}
Expectations
open http://localhost:8090/t1 in browser, return
{"result":"mid"}
Actual result
{"result":"mid"}{"result":"t2"}
Environment
- go version:1.14
- gin version (or commit ref):v1.7.4
- operating system:win10
Source: gin-gonic/gin