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>
Jeff King committed
Sep 28, 2013 at 04:31 UTC
132b70a2ed6d952e8142981474b41884ff93b780
1 file changed
+14
-7
http.c
+14
-7
@@ -820,6 +820,18 @@ int handle_curl_result(struct slot_results *results)
820
}
821
}
822
823
+static CURLcode curlinfo_strbuf(CURL *curl, CURLINFO info, struct strbuf *buf)
824
+{
825
+ char *ptr;
826
+ CURLcode ret;
827
+
828
+ strbuf_reset(buf);
829
+ ret = curl_easy_getinfo(curl, info, &ptr);
830
+ if (!ret && ptr)
831
+ strbuf_addstr(buf, ptr);
832
+ return ret;
833
+}
834
+
835
/* http_request() targets */
836
#define HTTP_REQUEST_STRBUF 0
837
#define HTTP_REQUEST_FILE 1
@@ -878,13 +890,8 @@ static int http_request(const char *url, struct strbuf *type,
890
ret = HTTP_START_FAILED;
891
}
892
881
- if (type) {
882
- char *t;
883
- strbuf_reset(type);
884
- curl_easy_getinfo(slot->curl, CURLINFO_CONTENT_TYPE, &t);
885
- if (t)
886
- strbuf_addstr(type, t);
887
- }
893
+ if (type)
894
+ curlinfo_strbuf(slot->curl, CURLINFO_CONTENT_TYPE, type);
895
896
curl_slist_free_all(headers);
897
strbuf_release(&buf);