git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/9] http_request: factor out curlinfo_strbuf

From
Jeff King <peff@peff.net>
Date
Sep 28, 2013, 08:31 UTC
Message-ID
<20130928083111.GB2131@sigill.intra.peff.net>
In-Reply-To
<20130928082956.GA22610@sigill.intra.peff.net>

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>
---
 http.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/http.c b/http.c
index a985c40..d325669 100644
--- a/http.c
+++ b/http.c
@@ -837,6 +837,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
@@ -895,13 +907,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);
-- 
1.8.4.rc3.19.g9da5bf6
Previous: Jeff KingNext: Jeff King
Message 3 of 17 in “following http redirects”
  1. 0/9 following http redirectsJeff King, Sep 28, 2013
  2. 1/9 http_get_file: style fixesJeff King, Sep 28, 2013
  3. 2/9 http_request: factor out curlinfo_strbufJeff King, Sep 28, 2013
  4. 3/9 http: refactor options to http_get_*Jeff King, Sep 28, 2013
  5. 4/9 http: hoist credential request out of handle_curl_resultJeff King, Sep 28, 2013
  6. 5/9 http: provide effective url to callersJeff King, Sep 28, 2013
  7. 6/9 http: update base URLs when we see redirectsJeff King, Sep 28, 2013
  8. brian m. carlsonSep 29, 2013
  9. Eric SunshineSep 29, 2013
  10. Jeff KingSep 29, 2013
  11. Eric SunshineSep 29, 2013
  12. Junio C HamanoOct 18, 2013
  13. Jeff KingOct 18, 2013
  14. Junio C HamanoOct 18, 2013
  15. 7/9 remote-curl: make refs_url a strbufJeff King, Sep 28, 2013
  16. 8/9 remote-curl: store url as a strbufJeff King, Sep 28, 2013
  17. 9/9 remote-curl: rewrite base url from info/refs redirectsJeff King, Sep 28, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.