A 3xx response with a Location header is asking the client to go somewhere else. Today you detect that case, the first step toward following a redirect.
Report whether a response is a followable redirect and expose its Location.
A redirect is the server telling the client “what you asked for lives elsewhere,
go here instead.” It is signalled by a 3xx status code together with a
Location header naming the new target. So 302 Found with Location: http://example.com/new is a redirect to that URL. A 200 is not a redirect, and a
3xx with no Location has nowhere to send you, so it is not followable.
Detecting the redirect is the easy first step; the interesting parts follow. The
Location may be a relative reference that has to be resolved against the current
URL (next lesson), and the status code decides whether the follow-up keeps the
original method or switches to GET (the lesson after). But it all starts with
noticing that a response is asking to be followed.
// a followable redirect is: status in 300..399 AND a Location// header is present. return the Location value too.func (r *Response) redirect() (location string, ok bool) {// ok := status >= 300 && status < 400 && Get("Location") != ""}