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
This commit is contained in:
Junio C Hamano 2013-09-09 14:32:08 -07:00
commit 4301262640
4 changed files with 36 additions and 1 deletions

View File

@ -1449,7 +1449,11 @@ http.cookiefile::
of the file to read cookies from should be plain HTTP headers or of the file to read cookies from should be plain HTTP headers or
the Netscape/Mozilla cookie file format (see linkgit:curl[1]). the Netscape/Mozilla cookie file format (see linkgit:curl[1]).
NOTE that the file specified with http.cookiefile is only used as NOTE that the file specified with http.cookiefile is only used as
input. No cookies will be stored in the file. input unless http.saveCookies is set.
http.savecookies::
If set, store cookies received during requests to the file specified by
http.cookiefile. Has no effect if http.cookiefile is unset.
http.sslVerify:: http.sslVerify::
Whether to verify the SSL certificate when fetching or pushing Whether to verify the SSL certificate when fetching or pushing

7
http.c
View File

@ -45,6 +45,7 @@ static long curl_low_speed_time = -1;
static int curl_ftp_no_epsv; static int curl_ftp_no_epsv;
static const char *curl_http_proxy; static const char *curl_http_proxy;
static const char *curl_cookie_file; static const char *curl_cookie_file;
static int curl_save_cookies;
static struct credential http_auth = CREDENTIAL_INIT; static struct credential http_auth = CREDENTIAL_INIT;
static int http_proactive_auth; static int http_proactive_auth;
static const char *user_agent; static const char *user_agent;
@ -200,6 +201,10 @@ static int http_options(const char *var, const char *value, void *cb)
if (!strcmp("http.cookiefile", var)) if (!strcmp("http.cookiefile", var))
return git_config_string(&curl_cookie_file, var, value); return git_config_string(&curl_cookie_file, var, value);
if (!strcmp("http.savecookies", var)) {
curl_save_cookies = git_config_bool(var, value);
return 0;
}
if (!strcmp("http.postbuffer", var)) { if (!strcmp("http.postbuffer", var)) {
http_post_buffer = git_config_int(var, value); http_post_buffer = git_config_int(var, value);
@ -513,6 +518,8 @@ struct active_request_slot *get_active_slot(void)
slot->callback_data = NULL; slot->callback_data = NULL;
slot->callback_func = NULL; slot->callback_func = NULL;
curl_easy_setopt(slot->curl, CURLOPT_COOKIEFILE, curl_cookie_file); curl_easy_setopt(slot->curl, CURLOPT_COOKIEFILE, curl_cookie_file);
if (curl_save_cookies)
curl_easy_setopt(slot->curl, CURLOPT_COOKIEJAR, curl_cookie_file);
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, pragma_header); curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, pragma_header);
curl_easy_setopt(slot->curl, CURLOPT_ERRORBUFFER, curl_errorstr); curl_easy_setopt(slot->curl, CURLOPT_ERRORBUFFER, curl_errorstr);
curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, NULL); curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, NULL);

View File

@ -22,6 +22,9 @@ ErrorLog error.log
<IfModule !mod_version.c> <IfModule !mod_version.c>
LoadModule version_module modules/mod_version.so LoadModule version_module modules/mod_version.so
</IfModule> </IfModule>
<IfModule !mod_headers.c>
LoadModule headers_module modules/mod_headers.so
</IfModule>
<IfVersion < 2.4> <IfVersion < 2.4>
LockFile accept.lock LockFile accept.lock
@ -87,6 +90,11 @@ Alias /auth/dumb/ www/auth/dumb/
SetEnv GIT_HTTP_EXPORT_ALL SetEnv GIT_HTTP_EXPORT_ALL
SetEnv GIT_NAMESPACE ns SetEnv GIT_NAMESPACE ns
</LocationMatch> </LocationMatch>
<LocationMatch /smart_cookies/>
SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
SetEnv GIT_HTTP_EXPORT_ALL
Header set Set-Cookie name=value
</LocationMatch>
ScriptAliasMatch /smart_*[^/]*/(.*) ${GIT_EXEC_PATH}/git-http-backend/$1 ScriptAliasMatch /smart_*[^/]*/(.*) ${GIT_EXEC_PATH}/git-http-backend/$1
ScriptAlias /broken_smart/ broken-smart-http.sh/ ScriptAlias /broken_smart/ broken-smart-http.sh/
<Directory ${GIT_EXEC_PATH}> <Directory ${GIT_EXEC_PATH}>

View File

@ -187,6 +187,22 @@ test_expect_success 'dumb clone via http-backend respects namespace' '
test_cmp expect actual test_cmp expect actual
' '
cat >cookies.txt <<EOF
127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
EOF
cat >expect_cookies.txt <<EOF
127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
127.0.0.1 FALSE /smart_cookies/repo.git/info/ FALSE 0 name value
EOF
test_expect_success 'cookies stored in http.cookiefile when http.savecookies set' '
git config http.cookiefile cookies.txt &&
git config http.savecookies true &&
git ls-remote $HTTPD_URL/smart_cookies/repo.git master &&
tail -3 cookies.txt > cookies_tail.txt
test_cmp expect_cookies.txt cookies_tail.txt
'
test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE
test_expect_success EXPENSIVE 'create 50,000 tags in the repo' ' test_expect_success EXPENSIVE 'create 50,000 tags in the repo' '