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: client not following redirects by default #12705

Closed
piazzamp opened this issue Sep 21, 2015 · 4 comments
Closed

net/http: client not following redirects by default #12705

piazzamp opened this issue Sep 21, 2015 · 4 comments
Milestone

Comments

@piazzamp
Copy link

this line in client.go causes some confusion in the default behavior of client.Do(). The documentation says that the default HTTP method of a request is GET and that, when clients issue GET requests, redirects will be followed.

It seems that the aforementioned line should include req.Method == ""

@piazzamp
Copy link
Author

here's a simple test that doesn't run in the play sandbox, but will run on your machine that allows outbound connections:
http://play.golang.org/p/njZvpYq2WN

note the behavior change when uncommenting line 16

@rakyll
Copy link
Contributor

rakyll commented Sep 21, 2015

The method could be either one of the predefined methods or an extension method. I don't understand why do we support empty string as a method in the first place.

From http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html,

Request-Line   = Method SP Request-URI SP HTTP-Version CRLF

 Method         = "OPTIONS"                ; Section 9.2
                | "GET"                    ; Section 9.3
                | "HEAD"                   ; Section 9.4
                | "POST"                   ; Section 9.5
                | "PUT"                    ; Section 9.6
                | "DELETE"                 ; Section 9.7
                | "TRACE"                  ; Section 9.8
                | "CONNECT"                ; Section 9.9
                | extension-method
 extension-method = token

/cc @bradfitz

@rakyll rakyll changed the title http client not following redirects by default net/http: client not following redirects by default Sep 21, 2015
@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Sep 22, 2015
@bradfitz
Copy link
Contributor

bradfitz commented Dec 3, 2015

@rakyll, because we've always guaranteed and documented that, for better or worse:

https://golang.org/pkg/net/http/#Request

        // Method specifies the HTTP method (GET, POST, PUT, etc.).
        // For client requests an empty string means GET.
        Method string

So we should be consistent.

@gopherbot
Copy link

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

@golang golang locked and limited conversation to collaborators Dec 14, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants