gin icon indicating copy to clipboard operation
gin copied to clipboard

Handle method has bug

Open cgopher opened this issue 2 years ago • 2 comments

  • With issues:
    • Use the search tool before opening a new issue.
    • Please provide source code and commit sha if you found a bug.
    • Review existing issues and provide feedback or react to them.

Description

How to reproduce

package main

import (
	"net/http"

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

func main() {
	r := gin.Default()
	r.Handle("GOT", "/test", func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{
			"message": "pong",
		})
	})
	_ = r.Run(":9999") // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}

Expectations


Actual result

GOT method not exists

Environment

  • go version:
  • gin version (or commit ref):
  • operating system:

cgopher avatar Nov 14 '23 07:11 cgopher

Hi,

gin works as expected. You register your handle to react on HTTP-Method "GOT", which is not defined in the HTTP-Spec (see https://www.rfc-editor.org/rfc/rfc9110.html#name-methods).

r.Handle("GOT"...

Change this to "GET" or better "http.MethodGet" (and corresponding import), your bug is fixed.

BTW, if you have curl installed you could also try to call the "GOT"-HTTP-Method with:

curl -X GOT http://localhost:9999/test

Kristian

kkoehler avatar Nov 15 '23 07:11 kkoehler

Hi,

gin works as expected. You register your handle to react on HTTP-Method "GOT", which is not defined in the HTTP-Spec (see https://www.rfc-editor.org/rfc/rfc9110.html#name-methods).

r.Handle("GOT"...

Change this to "GET" or better "http.MethodGet" (and corresponding import), your bug is fixed.

BTW, if you have curl installed you could also try to call the "GOT"-HTTP-Method with:

curl -X GOT http://localhost:9999/test

Kristian

I think methods that do not belong to http should be filtered out

cgopher avatar Nov 20 '23 11:11 cgopher