]> git.ipfire.org Git - thirdparty/git.git/commitdiff
http: provide effective url to callers
authorJeff King <peff@peff.net>
Sat, 28 Sep 2013 08:32:02 +0000 (04:32 -0400)
committerJonathan Nieder <jrnieder@gmail.com>
Mon, 14 Oct 2013 23:55:23 +0000 (16:55 -0700)
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>
http.c
http.h

diff --git a/http.c b/http.c
index 5703074d95d1e1782c754b28921ccde9d7b28c57..1569c5610888374f6446af6ce65ef55717f716f1 100644 (file)
--- a/http.c
+++ b/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);
 
diff --git a/http.h b/http.h
index 17116abc570bf3d5577051420d88d839a9603e80..974ede7736ec746c9ef067dd747c407db8df8c98 100644 (file)
--- 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_*() */