Skip to content

Commit 7886896

Browse files
peffjrn
authored andcommitted
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 <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]>
1 parent 2501aff commit 7886896

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

http.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,10 @@ static int http_request(const char *url,
894894
curlinfo_strbuf(slot->curl, CURLINFO_CONTENT_TYPE,
895895
options->content_type);
896896

897+
if (options && options->effective_url)
898+
curlinfo_strbuf(slot->curl, CURLINFO_EFFECTIVE_URL,
899+
options->effective_url);
900+
897901
curl_slist_free_all(headers);
898902
strbuf_release(&buf);
899903

http.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ struct http_get_options {
133133

134134
/* If non-NULL, returns the content-type of the response. */
135135
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;
136142
};
137143

138144
/* Return values for http_get_*() */

0 commit comments

Comments
 (0)