Skip to content

The next middleware will be executed even if the Next method is not called in the middleware #4254

Open
@XuruiPro

Description

@XuruiPro

golang code

r := gin.New()
r.Use(func(ctx *gin.Context) {
	fmt.Println(1)
        // ctx.Next()    Must be called to execute the next step
})
r.Use(func(ctx *gin.Context) {
	fmt.Println(2)
})
r.GET("/test", func(ctx *gin.Context) {
	ctx.String(http.StatusOK, "hello world")
})
r.Run("127.0.0.1:2020")

result

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET    /test                     --> main.main.func3 (3 handlers)
[GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value.
Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies for details.
[GIN-debug] Listening and serving HTTP on 127.0.0.1:2020
1
2

question?

Why do we need to call Abort instead of interrupting without calling Next

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