go2:net/http.Client: Do not follow redirect by default!

Created on 25 Nov 2020  路  5Comments  路  Source: golang/go

Currently i use go1.15.3, Why net/http follow redirect by default ?, just why ?, It's a http client not a browser, cmon man, what are you thinking you should follow redirect in the first place ?

The Go I know are not like this, ~ Voltaire

This behavior confuse me for an hour, and I'm sure, I will use Go for the next 10years, or maybe 30years (if I still alive, or no robot/no code takes our job)

_Aye mate, Don't just dislike, share your opinion too_

Most helpful comment

This is clearly documented and arguably useful behaviour for the majority of cases. As an HTTP client, it understands HTTP semantics such as redirects, authentication, etc.

From the package documentation, near the top (emphasis mine)

For control over HTTP client headers, redirect policy, and other settings, create a Client:

From https://golang.org/pkg/net/http/#Client 3rd paragraph

A Client is higher-level than a RoundTripper (such as Transport) and additionally handles HTTP details such as cookies and redirects.

[...3 more paragraphs on redirect policy...]

All 5 comments

oh my gosh, I really feel like not using Go

Screenshot from 2020-11-26 00-28-31
And I just feel useless after knowing the google auto-complete

Sorry

This is clearly documented and arguably useful behaviour for the majority of cases. As an HTTP client, it understands HTTP semantics such as redirects, authentication, etc.

From the package documentation, near the top (emphasis mine)

For control over HTTP client headers, redirect policy, and other settings, create a Client:

From https://golang.org/pkg/net/http/#Client 3rd paragraph

A Client is higher-level than a RoundTripper (such as Transport) and additionally handles HTTP details such as cookies and redirects.

[...3 more paragraphs on redirect policy...]

cmon man, be real, _no one read HTTP Client library behavior before they paste the code into their editor_ , so I go back Googling this kind of thing, and, Oh man, something wrong with our society, common sense are not always right, so we need to fix this weird behavior starting from Go 2 (and Python4)

The Go project doesn't use the issue tracker for questions. See https://golang.org/wiki/Questions.

If you really want to propose a change to the default behavior of net/http, you can create a proposal. But beware that there is currently no plan to make backwards-incompatible changes to standard library packages.

Also, remember to be respectful and thoughtful: https://golang.org/conduct.

I just remembered that there's also this thread: https://github.com/golang/go/issues/5465

Was this page helpful?
0 / 5 - 0 ratings