Fix regression from https://golang.org/cl/16829 ("require valid methods
in NewRequest and Transport.RoundTrip").
An empty string is a valid method (it means "GET", per the docs).
Fixes #13311
Change-Id: I26b71dc4ccc146498b5d7e38fbe31ed11dd5a6cf
Reviewed-on: https://go-review.googlesource.com/16952
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
req.closeBody()
return nil, &badStringError{"unsupported protocol scheme", s}
}
- if !validMethod(req.Method) {
+ if req.Method != "" && !validMethod(req.Method) {
return nil, fmt.Errorf("net/http: invalid method %q", req.Method)
}
if req.URL.Host == "" {
"net"
. "net/http"
"net/http/httptest"
+ "net/http/httputil"
"net/url"
"os"
"reflect"
defer afterTest(t)
tr := &Transport{}
_, err := tr.RoundTrip(&Request{
- Method: "GET",
Header: make(Header),
URL: &url.URL{
Scheme: "http",
}
}
+// Issue 13311
+func TestTransportEmptyMethod(t *testing.T) {
+ req, _ := NewRequest("GET", "http://foo.com/", nil)
+ req.Method = "" // docs say "For client requests an empty string means GET"
+ got, err := httputil.DumpRequestOut(req, false) // DumpRequestOut uses Transport
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !strings.Contains(string(got), "GET ") {
+ t.Fatalf("expected substring 'GET '; got: %s", got)
+ }
+}
+
func TestTransportSocketLateBinding(t *testing.T) {
defer afterTest(t)