Skip to content

Commit 132b70a

Browse files
peffjrn
authored andcommitted
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 <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]>
1 parent 3d1fb76 commit 132b70a

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

http.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,18 @@ int handle_curl_result(struct slot_results *results)
820820
}
821821
}
822822

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+
823835
/* http_request() targets */
824836
#define HTTP_REQUEST_STRBUF 0
825837
#define HTTP_REQUEST_FILE 1
@@ -878,13 +890,8 @@ static int http_request(const char *url, struct strbuf *type,
878890
ret = HTTP_START_FAILED;
879891
}
880892

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);
888895

889896
curl_slist_free_all(headers);
890897
strbuf_release(&buf);

0 commit comments

Comments
 (0)