Skip to content

Commit 6f4c347

Browse files
peffgitster
authored andcommitted
http: use newer curl options for setting credentials
We give the username and password to curl by sticking them in a buffer of the form "user:pass" and handing the result to CURLOPT_USERPWD. Since curl 7.19.1, there is a split mechanism, where you can specify each element individually. This has the advantage that a username can contain a ":" character. It also is less code for us, since we can hand our strings over to curl directly. And since curl 7.17.0 and higher promise to copy the strings for us, we we don't even have to worry about memory ownership issues. Unfortunately, we have to keep the ugly code for old curl around, but as it is now nicely #if'd out, we can easily get rid of it when we decide that 7.19.1 is "old enough". Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aa0834a commit 6f4c347

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

http.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,23 @@ static int http_options(const char *var, const char *value, void *cb)
210210

211211
static void init_curl_http_auth(CURL *result)
212212
{
213-
if (http_auth.username) {
213+
if (!http_auth.username)
214+
return;
215+
216+
credential_fill(&http_auth);
217+
218+
#if LIBCURL_VERSION_NUM >= 0x071301
219+
curl_easy_setopt(result, CURLOPT_USERNAME, http_auth.username);
220+
curl_easy_setopt(result, CURLOPT_PASSWORD, http_auth.password);
221+
#else
222+
{
214223
static struct strbuf up = STRBUF_INIT;
215-
credential_fill(&http_auth);
216224
strbuf_reset(&up);
217225
strbuf_addf(&up, "%s:%s",
218226
http_auth.username, http_auth.password);
219227
curl_easy_setopt(result, CURLOPT_USERPWD, up.buf);
220228
}
229+
#endif
221230
}
222231

223232
static int has_cert_password(void)

0 commit comments

Comments
 (0)