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>
Jeff King committed
Sep 28, 2013 at 04:32 UTC
78868962c03e5bdddad5c5d02c1d5a0c72a7ac26
2 files changed
+10
http.c
+4
@@ -894,6 +894,10 @@ static int http_request(const char *url,
894
curlinfo_strbuf(slot->curl, CURLINFO_CONTENT_TYPE,
895
options->content_type);
896
897
+ if (options && options->effective_url)
898
+ curlinfo_strbuf(slot->curl, CURLINFO_EFFECTIVE_URL,
899
+ options->effective_url);
900
+
901
curl_slist_free_all(headers);
902
strbuf_release(&buf);
903
http.h
+6
@@ -133,6 +133,12 @@ struct http_get_options {
133
134
/* If non-NULL, returns the content-type of the response. */
135
struct strbuf *content_type;
136
+
137
+ /*
138
+ * If non-NULL, returns the URL we ended up at, including any
139
+ * redirects we followed.
140
+ */
141
+ struct strbuf *effective_url;
142
};
143
144
/* Return values for http_get_*() */