• 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

Not support customize http method!such as lowercase “get”.

How to reproduce

package main

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

func main() {
    g := gin.Default()
    g.get("/hello/:name", func(c *gin.Context) {
        c.String(200, "Hello %s", c.Param("name"))
    })
    g.Post("/hello/:name", func(c *gin.Context) {
        c.String(200, "Hello %s", c.Param("name"))
    })
    g.UpDaTe("/hello/:name", func(c *gin.Context) {
        c.String(200, "Hello %s", c.Param("name"))
    })
    g.Run(":9000")
}

**Comment From: eleven26**

**`Get`**

**Comment From: SaltySooda**

@thinkerou @eleven26 
?
gin only support some uppercase http method:
`const (
    MethodGet     = "GET"
    MethodHead    = "HEAD"
    MethodPost    = "POST"
    MethodPut     = "PUT"
    MethodPatch   = "PATCH" // RFC 5789
    MethodDelete  = "DELETE"
    MethodConnect = "CONNECT"
    MethodOptions = "OPTIONS"
    MethodTrace   = "TRACE"
)`
So,what if I want to receive“get” request from outside?

**Comment From: eleven26**

> @thinkerou @eleven26 ? gin only support some uppercase http method: `const ( MethodGet = "GET" MethodHead = "HEAD" MethodPost = "POST" MethodPut = "PUT" MethodPatch = "PATCH" // RFC 5789 MethodDelete = "DELETE" MethodConnect = "CONNECT" MethodOptions = "OPTIONS" MethodTrace = "TRACE" )` So,what if I want to receive“get” request from outside?

Are you saying that gin can't handle `get` requests? If yes, please post your code or http message or other useful information.

**Comment From: SaltySooda**

package main

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

func main() { //server g :=gin.Default() g.GET("/hello/:name", func(c *gin.Context) { c.String(200, "Hello %s", c.Param("name")) }) go g.Run(":9000") time.Sleep(time.Second) //client client1() client2() for true { time.Sleep(time.Second) } }

func client1() { req,err := http.NewRequest("get","http://127.0.0.1:9000/hello/dog",strings.NewReader("123")) if err != nil { println(err) return } c := http.DefaultClient _,err = c.Do(req) if err != nil { println(err) }

} func client2() { req,err := http.NewRequest("GET","http://127.0.0.1:9000/hello/cat",strings.NewReader("123")) if err != nil { println(err) return } c := http.DefaultClient _,err = c.Do(req) if err != nil { println(err) } }



the result is :

[GIN] 2022/07/12 - 14:21:25 | 404 | 0s | 127.0.0.1 | get "/hello/dog" [GIN] 2022/07/12 - 14:21:25 | 200 | 0s | 127.0.0.1 | GET "/hello/cat" ```

@eleven26

Comment From: eleven26

This is indeed the case, but from the perspective of HTTP usage, it is more inclined to use HTTP methods with all uppercase letters, although this is not an HTTP standard.

n RFC2616, the HTTP request method does not say that it must be capitalized, but that it is case-sensitive. This means that the capitalization of HTTP methods is entirely up to the implementation of the HTTP server.

And let's take a look at the names of the request methods in golang, which are all capitalized. For example, the value of http.MethodGet is GET, so why not use the constants of the HTTP method instead of "get"? After all, it's a more traditional practice.

Of course, we can also implement HTTP methods compatible with these lowercase, just change the handleHTTPRequest method in gin.go, and convert httpMethod to strings.ToUpper(httpMethod), In this way, we can support it, but I personally think it is unnecessary. A better choice may be to modify your request method to "GET".

Comment From: SaltySooda

@eleven26 I understand!however in my situation,the request is from outside.I can not command them to change. So,as you say,HTTP request method is case-sensitive.that is why I asked if there is possible that GIN to support customize http method.

Comment From: eleven26

@359859461 I've submitted a pull request, don't know if it will eventually be merged into master, but until then, if you want to support lowercase HTTP methods in your app, the quickest way is to, before compiling your app, modify the handleHTTPRequest method in the local gin.go file and change the first line to httpMethod := strings.ToUpper(c.Request.Method).

Comment From: SaltySooda

@eleven26 the way you changed is against to the standard.please check #3244