When we ask curl to access a URL, it may follow one or more redirects to reach the final location. We have no idea this has happened, as curl takes care of the details and simply returns the final content to us. The final URL that we ended up with can be accessed via CURLINFO_EFFECTIVE_URL. Let's make that optionally available to callers of http_get_*, so that they can make further decisions based on the redirection. Signed-off-by: Jeff King <peff@xxxxxxxx> --- http.c | 4 ++++ http.h | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/http.c b/http.c index 5504b2c..65a0048 100644 --- a/http.c +++ b/http.c @@ -911,6 +911,10 @@ static int http_request(const char *url, curlinfo_strbuf(slot->curl, CURLINFO_CONTENT_TYPE, options->content_type); + if (options && options->effective_url) + curlinfo_strbuf(slot->curl, CURLINFO_EFFECTIVE_URL, + options->effective_url); + curl_slist_free_all(headers); strbuf_release(&buf); diff --git a/http.h b/http.h index 17116ab..974ede7 100644 --- a/http.h +++ b/http.h @@ -133,6 +133,12 @@ struct http_get_options { /* If non-NULL, returns the content-type of the response. */ struct strbuf *content_type; + + /* + * If non-NULL, returns the URL we ended up at, including any + * redirects we followed. + */ + struct strbuf *effective_url; }; /* Return values for http_get_*() */ -- 1.8.4.rc3.19.g9da5bf6 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html