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

Comments

@mwmahlberg
Copy link

@mwmahlberg mwmahlberg commented Feb 16, 2021

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
@ericlagergren
Copy link
Contributor

@ericlagergren ericlagergren commented Feb 17, 2021

"foobar" is a valid HTTP method:

func validMethod(method string) bool {

@mwmahlberg
Copy link
Author

@mwmahlberg mwmahlberg commented Feb 19, 2021

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

@mwmahlberg mwmahlberg closed this Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants