git-2.22.0/http.c
/*
 * Update the "base" url to a more appropriate value, as deduced by
 * redirects seen when requesting a URL starting with "url".
 *
 * The "asked" parameter is a URL that we asked curl to access, and must begin
 * with "base".
 *
 * The "got" parameter is the URL that curl reported to us as where we ended
 * up.
 *
 * Returns 1 if we updated the base url, 0 otherwise.
 *
 * Our basic strategy is to compare "base" and "asked" to find the bits
 * specific to our request. We then strip those bits off of "got" to yield the
 * new base. So for example, if our base is "http://example.com/foo.git",
 * and we ask for "http://example.com/foo.git/info/refs", we might end up
 * with "https://other.example.com/foo.git/info/refs". We would want the
 * new URL to become "https://other.example.com/foo.git".
 *
 * Note that this assumes a sane redirect scheme. It's entirely possible
 * in the example above to end up at a URL that does not even end in
 * "info/refs".  In such a case we die. There's not much we can do, such a
 * scheme is unlikely to represent a real git repository, and failing to
 * rewrite the base opens options for malicious redirects to do funny things.
 */
Update the "base" url to a more appropriate value, as deduced by
redirects seen when requesting a URL starting with "url".

The "asked" parameter is a URL that we asked curl to access, and must begin
with "base".

The "got" parameter is the URL that curl reported to us as where we ended
up.

Returns 1 if we updated the base url, 0 otherwise.

Our basic strategy is to compare "base" and "asked" to find the bits
specific to our request. We then strip those bits off of "got" to yield the
new base.

Note that this assumes a sane redirect scheme. It's entirely possible
in the example above to end up at a URL that does not even end in
"info/refs".  In such a case we die. There's not much we can do, such a
scheme is unlikely to represent a real git repository, and failing to
rewrite the base opens options for malicious redirects to do funny things.
Update the " base " url to a more appropriate value as deduced by redirects seen when requesting a URL starting with " url " . The " asked " parameter is a URL that we asked curl to access and must begin with " base " . The " got " parameter is the URL that curl reported to us as where we ended up . Returns 1 if we updated the base url 0 otherwise . Our basic strategy is to compare " base " and " asked " to find the bits specific to our request . We then strip those bits off of " got " to yield the new base . Note that this assumes a sane redirect scheme . It ' s entirely possible in the example above to end up at a URL that does not even end in " info / refs " . In such a case we die . There ' s not much we can do such a scheme is unlikely to represent a real git repository and failing to rewrite the base opens options for malicious redirects to do funny things .
static int update_url_from_redirect(struct strbuf *base,
				    const char *asked,
				    const struct strbuf *got)
{
	const char *tail;
	size_t new_len;
	if (!strcmp(asked, got->buf))
		return 0;
	if (!skip_prefix(asked, base->buf, &tail))
		BUG("update_url_from_redirect: %s is not a superset of %s",
		    asked, base->buf);
	new_len = got->len;
	if (!strip_suffix_mem(got->buf, &new_len, tail))
		die(_("unable to update url base from redirection:\n"
		      "  asked for: %s\n"
		      "   redirect: %s"),
		    asked, got->buf);
	strbuf_reset(base);
	strbuf_add(base, got->buf, new_len);
	return 1;
}
static int update_url_from_redirect ( struct strbuf * base , const char * asked , const struct strbuf * got ) { const char * tail ; size_t new_len ; if ( ! strcmp ( asked , got -> buf ) ) return 0 ; if ( ! skip_prefix ( asked , base -> buf , & tail ) ) BUG ( " " , asked , base -> buf ) ; new_len = got -> len ; if ( ! strip_suffix_mem ( got -> buf , & new_len , tail ) ) die ( _ ( " \n " " \n " " " ) , asked , got -> buf ) ; strbuf_reset ( base ) ; strbuf_add ( base , got -> buf , new_len ) ; return 1 ; }
Update the "base" url to a more appropriate value, as deduced by
 redirects seen when requesting a URL starting with "url".
Update the " base " url to a more appropriate value as deduced by redirects seen when requesting a URL starting with " url " .