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

net/http: invalid http request methods accepted in NewRequest and NewRequestWithContext #44291

Closed
mwmahlberg opened this issue Feb 16, 2021 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@mwmahlberg
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.15.7 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/Users//Documents/go/bin"
GOCACHE="/Users//Library/Caches/go-build"
GOENV="/Users//Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/markus.mahlberg/Documents/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users//Documents/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/local/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/local/lib/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="/usr/bin/clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users//go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/dr/k5sk_14s2t1dzqzqxfbq5j5c0000gn/T/go-build193393271=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

	req, err := http.NewRequest("foobar", "http://www.example.com", nil)
	if req!= nil && err == nil {
		fmt.Printf("Method %s was accepted by 'http.NewRequest'", req.Method)
	}

https://play.golang.org/p/CEpOCUm_RmA

What did you expect to see?

I expected reqto be nil and err.Error() to be "net/http: invalid method foobar" as per

go/src/net/http/request.go

Lines 845 to 847 in fa6752a

if !validMethod(method) {
return nil, fmt.Errorf("net/http: invalid method %q", method)
}

What did you see instead?

A request with an invalid method.

@seankhliao seankhliao changed the title Invalid http request methods accepted in http.NewRequest and http.NewRequestWithContext net/http: invalid http request methods accepted in NewRequest and NewRequestWithContext Feb 16, 2021
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 16, 2021
@ericlagergren
Copy link
Contributor

"foobar" is a valid HTTP method:

func validMethod(method string) bool {

@mwmahlberg
Copy link
Author

@ericlagergren True. Forgot the extensions. Works as intended.

@golang golang locked and limited conversation to collaborators Feb 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants