github.com/yandex/pandora@v0.5.32/lib/netutil/validator.go (about)

     1  package netutil
     2  
     3  import (
     4  	"strings"
     5  
     6  	"golang.org/x/net/http/httpguts"
     7  )
     8  
     9  func isNotToken(r rune) bool {
    10  	return !httpguts.IsTokenRune(r)
    11  }
    12  
    13  // ValidHTTPMethod just copy net/http/request.go validMethod(method string) bool
    14  func ValidHTTPMethod(method string) bool {
    15  	if method == "" {
    16  		// We document that "" means "GET" for Request.Method, and people have
    17  		// relied on that from NewRequest, so keep that working.
    18  		// We still enforce validMethod for non-empty methods.
    19  		method = "GET"
    20  	}
    21  	/*
    22  	     Method         = "OPTIONS"                ; Section 9.2
    23  	                    | "GET"                    ; Section 9.3
    24  	                    | "HEAD"                   ; Section 9.4
    25  	                    | "POST"                   ; Section 9.5
    26  	                    | "PUT"                    ; Section 9.6
    27  	                    | "DELETE"                 ; Section 9.7
    28  	                    | "TRACE"                  ; Section 9.8
    29  	                    | "CONNECT"                ; Section 9.9
    30  	                    | extension-method
    31  	   extension-method = token
    32  	     token          = 1*<any CHAR except CTLs or separators>
    33  	*/
    34  	return len(method) > 0 && strings.IndexFunc(method, isNotToken) == -1
    35  }