package main
import (
"log"
"net/http"
)
func main() {
// invalid method called "bad"
req, err := http.NewRequest("bad", "https://www.google.com", nil)
if err != nil {
log.Printf("E! got err: %v", err)
} else {
log.Printf("I! request method: %s", req.Method)
}
}
https://play.golang.org/p/NM8_4pkN5uM
err is nil here, can someone explain?
Thanks!
bad is not considered as a bad http method.
Any string of non zero length having characters from !#$%&*+-.0123456789ABCDEFGHIJKLMNOPQRSTUWVXYZ^_`abcdefghijklmnopqrstuvwxyz|~ is considered valid
Following is the function used to validate an HTTP METHOD
func validMethod(method string) bool {
/*
Method = "OPTIONS" ; Section 9.2
| "GET" ; Section 9.3
| "HEAD" ; Section 9.4
| "POST" ; Section 9.5
| "PUT" ; Section 9.6
| "DELETE" ; Section 9.7
| "TRACE" ; Section 9.8
| "CONNECT" ; Section 9.9
| extension-method
extension-method = token
token = 1*<any CHAR except CTLs or separators>
*/
return len(method) > 0 && strings.IndexFunc(method, isNotToken) == -1
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With