A redirect's Location is often a relative path, not a full URL. Today you resolve it against the current URL so the client always ends up with an absolute target to dial.
Resolve a Location against the current URL, handling both absolute URLs and absolute-path references.
The Location header may be a full URL (http://other.com/x) or a relative
reference - most commonly an absolute path like /new. A client has to turn
whichever it gets into a concrete absolute URL it can connect to. If the Location
already has a scheme, it is absolute and you just parse it. If it starts with /, it
is an absolute path on the same server, so you keep the current URL’s scheme, host,
and port and swap in the new path.
Full relative-reference resolution (../, paths relative to the current directory)
is a corner of the URI standard we deliberately skip - absolute URLs and absolute
paths cover the overwhelming majority of real redirects, and stopping there keeps the
lesson to one clear idea. With the target resolved, the last redirect question is
whether to reuse the original method, which is next.
// if the Location has a scheme ("http://"...), it is absolute:// parse and use it as-is. otherwise, if it starts with "/", it// is an absolute path: keep the current scheme+host+port, replace// the path (and query) with the Location.func resolveLocation(current *URL, location string) *URL { /* ... */ }