Skip to content

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

Closed
@mwmahlberg

Description

@mwmahlberg

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions