Skip to content

Commit

Permalink
http: provide effective url to callers
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Jonathan Nieder committed Oct 14, 2013
1 parent 2501aff commit 7886896
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions http.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_*() */
Expand Down

0 comments on commit 7886896

Please sign in to comment.