diff options
author | Jeff King <peff@peff.net> | 2013-09-28 04:34:05 -0400 |
---|---|---|
committer | Jonathan Nieder <jrnieder@gmail.com> | 2013-10-14 16:56:47 -0700 |
commit | c93c92f30977adb2eb385a851f9f5e9975da7d5e (patch) | |
tree | 4f733f83e991829c0afc6062324f3c9732f46185 /http.h | |
parent | 78868962c03e5bdddad5c5d02c1d5a0c72a7ac26 (diff) | |
download | git-c93c92f30977adb2eb385a851f9f5e9975da7d5e.tar.gz |
http: update base URLs when we see redirects
If a caller asks the http_get_* functions to go to a
particular URL and we end up elsewhere due to a redirect,
the effective_url field can tell us where we went.
It would be nice to remember this redirect and short-cut
further requests for two reasons:
1. It's more efficient. Otherwise we spend an extra http
round-trip to the server for each subsequent request,
just to get redirected.
2. If we end up with an http 401 and are going to ask for
credentials, it is to feed them to the redirect target.
If the redirect is an http->https upgrade, this means
our credentials may be provided on the http leg, just
to end up redirected to https. And if the redirect
crosses server boundaries, then curl will drop the
credentials entirely as it follows the redirect.
However, it, it is not enough to simply record the effective
URL we saw and use that for subsequent requests. We were
originally fed a "base" url like:
http://example.com/foo.git
and we want to figure out what the new base is, even though
the URLs we see may be:
original: http://example.com/foo.git/info/refs
effective: http://example.com/bar.git/info/refs
Subsequent requests will not be for "info/refs", but for
other paths relative to the base. We must ask the caller to
pass in the original base, and we must pass the redirected
base back to the caller (so that it can generate more URLs
from it). Furthermore, we need to feed the new base to the
credential code, so that requests to credential helpers (or
to the user) match the URL we will be requesting.
This patch teaches http_request_reauth to do this munging.
Since it is the caller who cares about making more URLs, it
seems at first glance that callers could simply check
effective_url themselves and handle it. However, since we
need to update the credential struct before the second
re-auth request, we have to do it inside http_request_reauth.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Diffstat (limited to 'http.h')
-rw-r--r-- | http.h | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -139,6 +139,14 @@ struct http_get_options { * redirects we followed. */ struct strbuf *effective_url; + + /* + * If both base_url and effective_url are non-NULL, the base URL will + * be munged to reflect any redirections going from the requested url + * to effective_url. See the definition of update_url_from_redirect + * for details. + */ + struct strbuf *base_url; }; /* Return values for http_get_*() */ |