Until recently, we always permitted an empty string to NewRequest.
Keep that property, since it broke tests within in Google when trying
out Go 1.6, and probably would've broken others too.
Change-Id: Idddab1ae7b9423d5caac00af2c897fe1065b600b
Reviewed-on: https://go-review.googlesource.com/17699
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
// type's documentation for the difference between inbound and outbound
// request fields.
func NewRequest(method, urlStr string, body io.Reader) (*Request, error) {
+ if method == "" {
+ // We document that "" means "GET" for Request.Method, and people have
+ // relied on that from NewRequest, so keep that working.
+ // We still enforce validMethod for non-empty methods.
+ method = "GET"
+ }
if !validMethod(method) {
return nil, fmt.Errorf("net/http: invalid method %q", method)
}
if err == nil || !strings.Contains(err.Error(), "invalid method") {
t.Errorf("Transport error = %v; want invalid method", err)
}
+
+ req, err = NewRequest("", "http://foo.com/", nil)
+ if err != nil {
+ t.Errorf("NewRequest(empty method) = %v; want nil", err)
+ } else if req.Method != "GET" {
+ t.Errorf("NewRequest(empty method) has method %q; want GET", req.Method)
+ }
}
func TestNewRequestContentLength(t *testing.T) {