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: more Method=="" vs Method=="GET" inconsistency #13621

Closed
rsc opened this issue Dec 15, 2015 · 3 comments

Comments

Projects
None yet
3 participants
@rsc
Copy link
Contributor

commented Dec 15, 2015

These diffs look like they might be needed. I looked at code mentioning the string "GET".

diff --git a/src/net/http/client.go b/src/net/http/client.go
index c3f849e..3472cd4 100644
--- a/src/net/http/client.go
+++ b/src/net/http/client.go
@@ -179,10 +179,11 @@ func (c *Client) send(req *Request) (*Response, error) {
 //
 // Generally Get, Post, or PostForm will be used instead of Do.
 func (c *Client) Do(req *Request) (resp *Response, err error) {
-   if req.Method == "" || req.Method == "GET" || req.Method == "HEAD" {
+   method := valueOrDefault(req.Method, "GET")
+   if method == "GET" || method == "HEAD" {
        return c.doFollowingRedirects(req, shouldRedirectGet)
    }
-   if req.Method == "POST" || req.Method == "PUT" {
+   if method == "POST" || method == "PUT" {
        return c.doFollowingRedirects(req, shouldRedirectPost)
    }
    return c.send(req)
diff --git a/src/net/http/request.go b/src/net/http/request.go
index 9f74042..cb62ab9 100644
--- a/src/net/http/request.go
+++ b/src/net/http/request.go
@@ -1054,9 +1054,11 @@ func (r *Request) closeBody() {
 }

 func (r *Request) isReplayable() bool {
-   return r.Body == nil &&
-       (r.Method == "GET" ||
-           r.Method == "HEAD" ||
-           r.Method == "OPTIONS" ||
-           r.Method == "TRACE")
+   if r.Body == nil {
+       switch valueOrDefault(r.Method, "GET") {
+       case "GET", "HEAD", "OPTIONS", "TRACE":
+           return true
+       }
+   }
+   return false
 }
diff --git a/src/net/http/transfer.go b/src/net/http/transfer.go
index 38b6f67..720c58c 100644
--- a/src/net/http/transfer.go
+++ b/src/net/http/transfer.go
@@ -56,7 +56,7 @@ func newTransferWriter(r interface{}) (t *transferWriter, err error) {
        if rr.ContentLength != 0 && rr.Body == nil {
            return nil, fmt.Errorf("http: Request.ContentLength=%d with nil Body", rr.ContentLength)
        }
-       t.Method = rr.Method
+       t.Method = valueOrDefault(rr.Method, "GET")
        t.Body = rr.Body
        t.BodyCloser = rr.Body
        t.ContentLength = rr.ContentLength

Brad, can you look and pick up the ones that are real bugs, if any? Thanks.

@rsc rsc added this to the Go1.6 milestone Dec 15, 2015

@bradfitz

This comment has been minimized.

Copy link
Member

commented Dec 15, 2015

Was any of this the result of a reported or observed bug? The changes seem fine at first glance. The transfer.go one is re-used by servers, so perhaps we don't want to map "" to "GET" on that side.

@rsc

This comment has been minimized.

Copy link
Contributor Author

commented Dec 15, 2015

No, it was just a result of me running grep to understand the state of the world while writing release notes. I'm going to leave any actual changes to you, as you see fit.

@gopherbot

This comment has been minimized.

Copy link

commented Dec 17, 2015

CL https://golang.org/cl/17981 mentions this issue.

@bradfitz bradfitz closed this in 18227bb Dec 17, 2015

@golang golang locked and limited conversation to collaborators Dec 29, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.