http: provide effective url to callers

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@peff.net>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
This commit is contained in:
Jeff King 2013-09-28 04:32:02 -04:00 коммит произвёл Jonathan Nieder
Родитель 2501aff8b7
Коммит 78868962c0
2 изменённых файлов: 10 добавлений и 0 удалений

4
http.c
Просмотреть файл

@ -894,6 +894,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);

6
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_*() */