You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a permanent redirect occurs, calling code should have a way to get notified of this
so that it can update the URL which is specified in some database. For example, a
crawler which receives a permanent redirect should not access the original URL on future
occasions; it should use the new URL specified in the redirect, but only if that
redirect is permanent.
net/http provides no easy way to obtain this information.
CheckRedirect is not suitable since it does not provide access to the Response
indicating the new Location, so the status code of that response cannot be polled to
determine whether it is a permanent redirect.
One way of solving this would be to add a PermanentURL field to Response. This would
contain the URL of the latest consecutive permanent redirect target. In the following
case:
Original URL -[Permanent Redirect To]-> Second URL -[Permanent Redirect To]->
Third URL -[Temporary Redirect To]-> Fourth URL -[Permanent Redirect To]-> Fifth
URL.
PermanentURL would contain the third URL.
This is an imperfect solution because it does not allow Permanent Redirects to be
recorded in situations where the redirect target is inaccessible and results in an error
and not a Response. Though it could be argued that that might be a feature as it causes
potentially erroneous Permanent Redirects to be ignored.
The text was updated successfully, but these errors were encountered:
This is already possible if you use the underlying RoundTripper (Transport) directly,
which doesn't have any special handling of redirects.
I'm not sure this needs to be "easy". If you need this capability, you're already
fancier than most people, who just want to fetch a resource.
The text was updated successfully, but these errors were encountered: