FAQ
I'm setting http.Client's CheckRedirect which just returns a error causing
the redirect to not be followed. While doing this I'm seeing odd behavior
between 1.0.2 and 1.0.3 version of go (on windows 64bit).

Using go 1.0.3 I'm seeing a http.Client#Do request which is made to a
endpoint which responds with a redirect (301|302), returns nil for the
http.Response value. In 1.0.2 the http.Response object is returned along
with the error. Is this expected? If so is there a better, more correct way
to prevent Client from following redirects, and receive the response that
the request received?

code:

func noRedirect(req *http.Request, via []*http.Request) error {
return errors.New("Redirect")
}

func createClient(cfg *Config) *http.Client {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}

client := &http.Client{
CheckRedirect: noRedirect,
Transport: tr,
}

return client
}

....

resp, err := p.Client.Do(req)
if err != nil && !strings.Contains(err.Error(), "Redirect") {
log.Println("Failed to proxy request", err, " request:", proxyToStr)
http.Error(w, "Internal Error", http.StatusInternalServerError)
return
}

// Do stuff with the request response

Cheers,
Jason

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Ian Lance Taylor at Mar 20, 2013 at 10:57 pm

    On Wed, Mar 20, 2013 at 2:14 PM, Jason Del Ponte wrote:
    I'm setting http.Client's CheckRedirect which just returns a error causing
    the redirect to not be followed. While doing this I'm seeing odd behavior
    between 1.0.2 and 1.0.3 version of go (on windows 64bit).

    Using go 1.0.3 I'm seeing a http.Client#Do request which is made to a
    endpoint which responds with a redirect (301|302), returns nil for the
    http.Response value. In 1.0.2 the http.Response object is returned along
    with the error. Is this expected? If so is there a better, more correct way
    to prevent Client from following redirects, and receive the response that
    the request received?
    I believe this is discussed at

    https://code.google.com/p/go/issues/detail?id=3795

    Ian

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jason Del Ponte at Mar 20, 2013 at 11:15 pm
    Reading over the issue, and associated discussion, it looks like it was
    regression that has since been reverted, but won't be included until, at
    least, the next released version of go.

    Thanks for the link!
    On Wed, Mar 20, 2013 at 3:57 PM, Ian Lance Taylor wrote:
    On Wed, Mar 20, 2013 at 2:14 PM, Jason Del Ponte wrote:

    I'm setting http.Client's CheckRedirect which just returns a error causing
    the redirect to not be followed. While doing this I'm seeing odd behavior
    between 1.0.2 and 1.0.3 version of go (on windows 64bit).

    Using go 1.0.3 I'm seeing a http.Client#Do request which is made to a
    endpoint which responds with a redirect (301|302), returns nil for the
    http.Response value. In 1.0.2 the http.Response object is returned along
    with the error. Is this expected? If so is there a better, more correct way
    to prevent Client from following redirects, and receive the response that
    the request received?
    I believe this is discussed at

    https://code.google.com/p/go/issues/detail?id=3795

    Ian


    --
    Cheers,
    Jason Del Ponte

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dave Cheney at Mar 21, 2013 at 1:04 am
    That is correct, the regression was not detected until after 1.0.3 was shipped.

    As currently planned, a release candidate for Go 1.1 will be available next month. I encourage you to try it.

    Cheers

    Dave
    On 21/03/2013, at 10:15, Jason Del Ponte wrote:

    Reading over the issue, and associated discussion, it looks like it was regression that has since been reverted, but won't be included until, at least, the next released version of go.

    Thanks for the link!
    On Wed, Mar 20, 2013 at 3:57 PM, Ian Lance Taylor wrote:
    On Wed, Mar 20, 2013 at 2:14 PM, Jason Del Ponte wrote:

    I'm setting http.Client's CheckRedirect which just returns a error causing
    the redirect to not be followed. While doing this I'm seeing odd behavior
    between 1.0.2 and 1.0.3 version of go (on windows 64bit).

    Using go 1.0.3 I'm seeing a http.Client#Do request which is made to a
    endpoint which responds with a redirect (301|302), returns nil for the
    http.Response value. In 1.0.2 the http.Response object is returned along
    with the error. Is this expected? If so is there a better, more correct way
    to prevent Client from following redirects, and receive the response that
    the request received?
    I believe this is discussed at

    https://code.google.com/p/go/issues/detail?id=3795

    Ian


    --
    Cheers,
    Jason Del Ponte
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 20, '13 at 9:15p
activeMar 21, '13 at 1:04a
posts4
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase