Skip to content

Commit 157a476

Browse files
committed
Merge branch 'cb/http-multi-curl-auth'
Fixes http authentication breakage when we keep multiple HTTP requests in flight using curl-multi. By Jeff King (3) and Clemens Buchacher (1) * cb/http-multi-curl-auth: http: use newer curl options for setting credentials http: clean up leak in init_curl_http_auth fix http auth with multiple curl handles http auth fails with multiple curl handles
2 parents 010b260 + 6f4c347 commit 157a476

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

http.c

Lines changed: 16 additions & 5 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) {
214-
struct strbuf up = STRBUF_INIT;
215-
credential_fill(&http_auth);
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+
{
223+
static struct strbuf up = STRBUF_INIT;
224+
strbuf_reset(&up);
216225
strbuf_addf(&up, "%s:%s",
217226
http_auth.username, http_auth.password);
218-
curl_easy_setopt(result, CURLOPT_USERPWD,
219-
strbuf_detach(&up, NULL));
227+
curl_easy_setopt(result, CURLOPT_USERPWD, up.buf);
220228
}
229+
#endif
221230
}
222231

223232
static int has_cert_password(void)
@@ -494,6 +503,8 @@ struct active_request_slot *get_active_slot(void)
494503
curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, NULL);
495504
curl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 0);
496505
curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
506+
if (http_auth.password)
507+
init_curl_http_auth(slot->curl);
497508

498509
return slot;
499510
}

t/t5550-http-fetch.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,22 @@ LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5550'}
1313
start_httpd
1414

1515
test_expect_success 'setup repository' '
16-
echo content >file &&
16+
echo content1 >file &&
1717
git add file &&
1818
git commit -m one
19+
echo content2 >file &&
20+
git add file &&
21+
git commit -m two
1922
'
2023

21-
test_expect_success 'create http-accessible bare repository' '
22-
mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
24+
test_expect_success 'create http-accessible bare repository with loose objects' '
25+
cp -a .git "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
2326
(cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
24-
git --bare init &&
27+
git config core.bare true &&
28+
mkdir -p hooks &&
2529
echo "exec git update-server-info" >hooks/post-update &&
26-
chmod +x hooks/post-update
30+
chmod +x hooks/post-update &&
31+
hooks/post-update
2732
) &&
2833
git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
2934
git push public master:master

0 commit comments

Comments
 (0)