Skip to content

Commit d402d55

Browse files
Nick HengeveldJunio C Hamano
authored andcommitted
Use config file settings for http
Use "http." config file settings if they exist. Environment variables still work, and they will override config file settings. Signed-off-by: Nick Hengeveld <nickh@reactrix.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent bc8f265 commit d402d55

File tree

1 file changed

+88
-21
lines changed

1 file changed

+88
-21
lines changed

http-fetch.c

Lines changed: 88 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static int active_requests = 0;
2525
static int data_received;
2626

2727
#ifdef USE_CURL_MULTI
28-
static int max_requests = DEFAULT_MAX_REQUESTS;
28+
static int max_requests = -1;
2929
static CURLM *curlm;
3030
#endif
3131
static CURL *curl_default;
@@ -85,11 +85,11 @@ struct active_request_slot
8585
static struct transfer_request *request_queue_head = NULL;
8686
static struct active_request_slot *active_queue_head = NULL;
8787

88-
static int curl_ssl_verify;
89-
static char *ssl_cert;
90-
static char *ssl_key;
91-
static char *ssl_capath;
92-
static char *ssl_cainfo;
88+
static int curl_ssl_verify = -1;
89+
static char *ssl_cert = NULL;
90+
static char *ssl_key = NULL;
91+
static char *ssl_capath = NULL;
92+
static char *ssl_cainfo = NULL;
9393

9494
struct buffer
9595
{
@@ -98,6 +98,60 @@ struct buffer
9898
void *buffer;
9999
};
100100

101+
static int http_options(const char *var, const char *value)
102+
{
103+
if (!strcmp("http.sslverify", var)) {
104+
if (curl_ssl_verify == -1) {
105+
curl_ssl_verify = git_config_bool(var, value);
106+
}
107+
return 0;
108+
}
109+
110+
if (!strcmp("http.sslcert", var)) {
111+
if (ssl_cert == NULL) {
112+
ssl_cert = xmalloc(strlen(value)+1);
113+
strcpy(ssl_cert, value);
114+
}
115+
return 0;
116+
}
117+
#if LIBCURL_VERSION_NUM >= 0x070902
118+
if (!strcmp("http.sslkey", var)) {
119+
if (ssl_key == NULL) {
120+
ssl_key = xmalloc(strlen(value)+1);
121+
strcpy(ssl_key, value);
122+
}
123+
return 0;
124+
}
125+
#endif
126+
#if LIBCURL_VERSION_NUM >= 0x070908
127+
if (!strcmp("http.sslcapath", var)) {
128+
if (ssl_capath == NULL) {
129+
ssl_capath = xmalloc(strlen(value)+1);
130+
strcpy(ssl_capath, value);
131+
}
132+
return 0;
133+
}
134+
#endif
135+
if (!strcmp("http.sslcainfo", var)) {
136+
if (ssl_cainfo == NULL) {
137+
ssl_cainfo = xmalloc(strlen(value)+1);
138+
strcpy(ssl_cainfo, value);
139+
}
140+
return 0;
141+
}
142+
143+
#ifdef USE_CURL_MULTI
144+
if (!strcmp("http.maxrequests", var)) {
145+
if (max_requests == -1)
146+
max_requests = git_config_int(var, value);
147+
return 0;
148+
}
149+
#endif
150+
151+
/* Fall back on the default ones */
152+
return git_default_config(var, value);
153+
}
154+
101155
static size_t fwrite_buffer(void *ptr, size_t eltsize, size_t nmemb,
102156
struct buffer *buffer)
103157
{
@@ -1114,43 +1168,56 @@ int main(int argc, char **argv)
11141168
char *http_max_requests = getenv("GIT_HTTP_MAX_REQUESTS");
11151169
if (http_max_requests != NULL)
11161170
max_requests = atoi(http_max_requests);
1117-
if (max_requests < 1)
1118-
max_requests = DEFAULT_MAX_REQUESTS;
11191171

11201172
curlm = curl_multi_init();
11211173
if (curlm == NULL) {
11221174
fprintf(stderr, "Error creating curl multi handle.\n");
11231175
return 1;
11241176
}
11251177
#endif
1178+
1179+
if (getenv("GIT_SSL_NO_VERIFY"))
1180+
curl_ssl_verify = 0;
1181+
1182+
ssl_cert = getenv("GIT_SSL_CERT");
1183+
#if LIBCURL_VERSION_NUM >= 0x070902
1184+
ssl_key = getenv("GIT_SSL_KEY");
1185+
#endif
1186+
#if LIBCURL_VERSION_NUM >= 0x070908
1187+
ssl_capath = getenv("GIT_SSL_CAPATH");
1188+
#endif
1189+
ssl_cainfo = getenv("GIT_SSL_CAINFO");
1190+
1191+
git_config(http_options);
1192+
1193+
if (curl_ssl_verify == -1)
1194+
curl_ssl_verify = 1;
1195+
1196+
#ifdef USE_CURL_MULTI
1197+
if (max_requests < 1)
1198+
max_requests = DEFAULT_MAX_REQUESTS;
1199+
#endif
1200+
11261201
pragma_header = curl_slist_append(pragma_header, "Pragma: no-cache");
11271202
no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
11281203
no_range_header = curl_slist_append(no_range_header, "Range:");
11291204

11301205
curl_default = curl_easy_init();
11311206

1132-
curl_ssl_verify = getenv("GIT_SSL_NO_VERIFY") ? 0 : 1;
11331207
curl_easy_setopt(curl_default, CURLOPT_SSL_VERIFYPEER, curl_ssl_verify);
11341208
#if LIBCURL_VERSION_NUM >= 0x070907
11351209
curl_easy_setopt(curl_default, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
11361210
#endif
11371211

1138-
if ((ssl_cert = getenv("GIT_SSL_CERT")) != NULL) {
1212+
if (ssl_cert != NULL)
11391213
curl_easy_setopt(curl_default, CURLOPT_SSLCERT, ssl_cert);
1140-
}
1141-
#if LIBCURL_VERSION_NUM >= 0x070902
1142-
if ((ssl_key = getenv("GIT_SSL_KEY")) != NULL) {
1214+
if (ssl_key != NULL)
11431215
curl_easy_setopt(curl_default, CURLOPT_SSLKEY, ssl_key);
1144-
}
1145-
#endif
1146-
#if LIBCURL_VERSION_NUM >= 0x070908
1147-
if ((ssl_capath = getenv("GIT_SSL_CAPATH")) != NULL) {
1216+
if (ssl_capath != NULL)
11481217
curl_easy_setopt(curl_default, CURLOPT_CAPATH, ssl_capath);
1149-
}
1150-
#endif
1151-
if ((ssl_cainfo = getenv("GIT_SSL_CAINFO")) != NULL) {
1218+
if (ssl_cainfo != NULL)
11521219
curl_easy_setopt(curl_default, CURLOPT_CAINFO, ssl_cainfo);
1153-
}
1220+
11541221
curl_easy_setopt(curl_default, CURLOPT_FAILONERROR, 1);
11551222

11561223
alt = xmalloc(sizeof(*alt));

0 commit comments

Comments
 (0)