diff options
author | Jeff King <peff@peff.net> | 2013-09-28 04:31:11 -0400 |
---|---|---|
committer | Jonathan Nieder <jrnieder@gmail.com> | 2013-09-30 13:04:45 -0700 |
commit | 132b70a2ed6d952e8142981474b41884ff93b780 (patch) | |
tree | 146fd3bf421de4fdf66c3fcadbcb19b264f3b44f | |
parent | http_get_file: style fixes (diff) | |
download | tgif-132b70a2ed6d952e8142981474b41884ff93b780.tar.xz |
http_request: factor out curlinfo_strbuf
When we retrieve the content-type of an http response, curl
gives us a pointer to internal storage, which we then copy
into a strbuf. Let's factor out the get-and-copy routine,
which can be used for getting other curl info.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
-rw-r--r-- | http.c | 21 |
1 files changed, 14 insertions, 7 deletions
@@ -820,6 +820,18 @@ int handle_curl_result(struct slot_results *results) } } +static CURLcode curlinfo_strbuf(CURL *curl, CURLINFO info, struct strbuf *buf) +{ + char *ptr; + CURLcode ret; + + strbuf_reset(buf); + ret = curl_easy_getinfo(curl, info, &ptr); + if (!ret && ptr) + strbuf_addstr(buf, ptr); + return ret; +} + /* http_request() targets */ #define HTTP_REQUEST_STRBUF 0 #define HTTP_REQUEST_FILE 1 @@ -878,13 +890,8 @@ static int http_request(const char *url, struct strbuf *type, ret = HTTP_START_FAILED; } - if (type) { - char *t; - strbuf_reset(type); - curl_easy_getinfo(slot->curl, CURLINFO_CONTENT_TYPE, &t); - if (t) - strbuf_addstr(type, t); - } + if (type) + curlinfo_strbuf(slot->curl, CURLINFO_CONTENT_TYPE, type); curl_slist_free_all(headers); strbuf_release(&buf); |