Skip to content

Commit 4301262

Browse files
committed
Merge branch 'db/http-savecookies'
* db/http-savecookies: t5551: Remove header from curl cookie file http: add http.savecookies option to write out HTTP cookies
2 parents 2233ad4 + 580cf0a commit 4301262

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

Documentation/config.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,11 @@ http.cookiefile::
14491449
of the file to read cookies from should be plain HTTP headers or
14501450
the Netscape/Mozilla cookie file format (see linkgit:curl[1]).
14511451
NOTE that the file specified with http.cookiefile is only used as
1452-
input. No cookies will be stored in the file.
1452+
input unless http.saveCookies is set.
1453+
1454+
http.savecookies::
1455+
If set, store cookies received during requests to the file specified by
1456+
http.cookiefile. Has no effect if http.cookiefile is unset.
14531457

14541458
http.sslVerify::
14551459
Whether to verify the SSL certificate when fetching or pushing

http.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ static long curl_low_speed_time = -1;
4545
static int curl_ftp_no_epsv;
4646
static const char *curl_http_proxy;
4747
static const char *curl_cookie_file;
48+
static int curl_save_cookies;
4849
static struct credential http_auth = CREDENTIAL_INIT;
4950
static int http_proactive_auth;
5051
static const char *user_agent;
@@ -200,6 +201,10 @@ static int http_options(const char *var, const char *value, void *cb)
200201

201202
if (!strcmp("http.cookiefile", var))
202203
return git_config_string(&curl_cookie_file, var, value);
204+
if (!strcmp("http.savecookies", var)) {
205+
curl_save_cookies = git_config_bool(var, value);
206+
return 0;
207+
}
203208

204209
if (!strcmp("http.postbuffer", var)) {
205210
http_post_buffer = git_config_int(var, value);
@@ -513,6 +518,8 @@ struct active_request_slot *get_active_slot(void)
513518
slot->callback_data = NULL;
514519
slot->callback_func = NULL;
515520
curl_easy_setopt(slot->curl, CURLOPT_COOKIEFILE, curl_cookie_file);
521+
if (curl_save_cookies)
522+
curl_easy_setopt(slot->curl, CURLOPT_COOKIEJAR, curl_cookie_file);
516523
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, pragma_header);
517524
curl_easy_setopt(slot->curl, CURLOPT_ERRORBUFFER, curl_errorstr);
518525
curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, NULL);

t/lib-httpd/apache.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ ErrorLog error.log
2222
<IfModule !mod_version.c>
2323
LoadModule version_module modules/mod_version.so
2424
</IfModule>
25+
<IfModule !mod_headers.c>
26+
LoadModule headers_module modules/mod_headers.so
27+
</IfModule>
2528

2629
<IfVersion < 2.4>
2730
LockFile accept.lock
@@ -87,6 +90,11 @@ Alias /auth/dumb/ www/auth/dumb/
8790
SetEnv GIT_HTTP_EXPORT_ALL
8891
SetEnv GIT_NAMESPACE ns
8992
</LocationMatch>
93+
<LocationMatch /smart_cookies/>
94+
SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
95+
SetEnv GIT_HTTP_EXPORT_ALL
96+
Header set Set-Cookie name=value
97+
</LocationMatch>
9098
ScriptAliasMatch /smart_*[^/]*/(.*) ${GIT_EXEC_PATH}/git-http-backend/$1
9199
ScriptAlias /broken_smart/ broken-smart-http.sh/
92100
<Directory ${GIT_EXEC_PATH}>

t/t5551-http-fetch.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,22 @@ test_expect_success 'dumb clone via http-backend respects namespace' '
187187
test_cmp expect actual
188188
'
189189

190+
cat >cookies.txt <<EOF
191+
127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
192+
EOF
193+
cat >expect_cookies.txt <<EOF
194+
195+
127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
196+
127.0.0.1 FALSE /smart_cookies/repo.git/info/ FALSE 0 name value
197+
EOF
198+
test_expect_success 'cookies stored in http.cookiefile when http.savecookies set' '
199+
git config http.cookiefile cookies.txt &&
200+
git config http.savecookies true &&
201+
git ls-remote $HTTPD_URL/smart_cookies/repo.git master &&
202+
tail -3 cookies.txt > cookies_tail.txt
203+
test_cmp expect_cookies.txt cookies_tail.txt
204+
'
205+
190206
test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE
191207

192208
test_expect_success EXPENSIVE 'create 50,000 tags in the repo' '

0 commit comments

Comments
 (0)