Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why is NoMethod marked as TODO #2871

Closed
togettoyou opened this issue Sep 17, 2021 · 3 comments
Closed

why is NoMethod marked as TODO #2871

togettoyou opened this issue Sep 17, 2021 · 3 comments

Comments

@togettoyou
Copy link
Contributor

Description

What is the role of NoMethod , it does not seem to be effective

I found it is marked as TODO :

// NoMethod sets the handlers called when... TODO.
func (engine *Engine) NoMethod(handlers ...HandlerFunc) {
	engine.noMethod = handlers
	engine.rebuild405Handlers()
}

How to reproduce

package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

func main() {
	r := gin.Default()
	r.NoRoute(func(c *gin.Context) {
		c.String(http.StatusOK, "NoRoute")
	})
	r.NoMethod(func(c *gin.Context) {
		fmt.Println("NoMethod")
		c.String(http.StatusOK, "NoMethod")
	})
	r.POST("/", func(c *gin.Context) {
		c.String(http.StatusOK, "/")
	})
	r.Run(":8080")
}

Expectations

$ curl http://localhost:8080
NoMethod

$ curl -X POST http://localhost:8080
/

$ curl -X PUT http://localhost:8080
NoMethod

Actual result

$ curl http://localhost:8080
NoRoute

$ curl -X POST http://localhost:8080
/

$ curl -X PUT http://localhost:8080
NoRoute

Environment

  • go version: go version go1.17 windows/amd64
  • gin version (or commit ref): v1.7.4
  • operating system: windows/amd64
@togettoyou
Copy link
Contributor Author

I found a way to turn it on :engine.HandleMethodNotAllowed = true

@togettoyou
Copy link
Contributor Author

So why is NoMethod marked as TODO?

@togettoyou togettoyou changed the title The role of NoMethod why is NoMethod marked as TODO Sep 17, 2021
@togettoyou
Copy link
Contributor Author

Should HandleMethodNotAllowed be turned on when using NoMethod ?

Bisstocuz pushed a commit to Bisstocuz/gin that referenced this issue Nov 22, 2021
Bisstocuz pushed a commit to Bisstocuz/gin that referenced this issue Nov 22, 2021
Bisstocuz pushed a commit to Bisstocuz/gin that referenced this issue Nov 22, 2021
Bisstocuz pushed a commit to Bisstocuz/gin that referenced this issue Nov 22, 2021
Bisstocuz pushed a commit to Bisstocuz/gin that referenced this issue Nov 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant