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 has broken compatibility on redirection handler #3795

Closed
niemeyer opened this issue Jul 3, 2012 · 10 comments
Closed

net/http has broken compatibility on redirection handler #3795

niemeyer opened this issue Jul 3, 2012 · 10 comments
Milestone

Comments

@niemeyer
Copy link
Contributor

niemeyer commented Jul 3, 2012

In go1*, one can return an error from a CheckRedirect implementation
and Do will return the last response, besides the error.

The following revision changed that:

    changeset:   13619:f7839a55036e
    user:        Brad Fitzpatrick <bradfitz@golang.org>
    date:        Tue Jun 19 09:10:14 2012 -0700
    summary:     net/http: clarify client return values in docs

After this change, the response is nil.

Besides the broken compatibility, with this change there's apparently no way to get to
an intermediate Response from the server, since preventing the redirect trashes it.

Looking at the change set, it seems that a similar behavioral change
was done for RoundTrip as well.
@niemeyer
Copy link
Contributor Author

niemeyer commented Jul 3, 2012

Comment 1:

Some discussion on the topic has happened on golang-dev:
https://groups.google.com/d/topic/golang-dev/j7VmXb9nd5M/discussion

Owner changed to ---.

@bradfitz
Copy link
Contributor

bradfitz commented Jul 3, 2012

Comment 2:

We can regrettably "fix" the Client redirect back to returning two non-nil values, but
it'll have to be documented/tested.
I'm less sure about RoundTrip.  It's always been documented on the interface about what
the expectations are for implementations of a RoundTripper.  What's the issue there?
I'll accept this bug for now, but patches welcome.  I won't start working on it until
Monday at least, and I'll change the status to "Started" here when I do start.

Owner changed to @bradfitz.

@niemeyer
Copy link
Contributor Author

niemeyer commented Jul 3, 2012

Comment 3:

RoundTrip didn't catch me, and I don't personally mind as much. It's still a stable API
being changed, though.
Thanks for looking at this, Brad.

@bradfitz
Copy link
Contributor

bradfitz commented Jul 3, 2012

Comment 4:

Now that I re-look at the docs (the same as shipped with Go 1), I care about RoundTrip
even less.  Note:
http://golang.org/pkg/net/http/#RoundTripper
    // [...] RoundTrip should not
    // attempt to interpret the response.  In particular,
    // RoundTrip must return err == nil if it obtained a response,
    // regardless of the response's HTTP status code.  A non-nil
    // err should be reserved for failure to obtain a response.
... there's even a "must" in there.

@patrickmn
Copy link

Comment 5:

Gustavo, the original change does say:
"Revision: f7839a55036e 
Author:   Brad Fitzpatrick <bradfitz@golang.org> 
Date:     Tue Jun 19 09:10:14 2012 
Log:      net/http: clarify client return values in docs 
Also, fixes one violation found during testing where both 
response and error could be non-nil when a CheckRedirect test 
failed.  This is arguably a minor API (behavior, not 
signature) change, but it wasn't documented either way and was 
inconsistent & non-Go like.  Any code depending on the old 
behavior was wrong anyway."

@bradfitz
Copy link
Contributor

bradfitz commented Jul 3, 2012

Comment 6:

Regarding that commit message: maybe I was wrong to declare all such code wrong, but I
couldn't think of a case where it would be useful to stop a redirect but care about
getting the response as you stopped it.

@niemeyer
Copy link
Contributor Author

Comment 7:

Brad, any news on this?

@bradfitz
Copy link
Contributor

Comment 8:

Easy fix. I just haven't done it yet. It would be a good project for today, though,
since I have limited Internet access.

Labels changed: added priority-soon, go1.1, removed priority-asap.

@bradfitz
Copy link
Contributor

Comment 9:

http://golang.org/cl/6429044

@bradfitz
Copy link
Contributor

Comment 10:

This issue was closed by revision dfd7f18.

Status changed to Fixed.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
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