Skip to content

Commit

Permalink
http_request: factor out curlinfo_strbuf
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Jonathan Nieder committed Sep 30, 2013
1 parent 3d1fb76 commit 132b70a
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 132b70a

Please sign in to comment.