@matheusbsbs / matheus-bagliano / commits / e0004e286c
Fork 0

Support for HTTP transfer timeouts based on transfer speed

Add configuration settings to abort HTTP requests if the transfer rate drops below a threshold for a specified length of time. Environment variables override config file settings. Signed-off-by: Nick Hengeveld <nickh@reactrix.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Nick Hengeveld committed Oct 19, 2005 at 14:27 UTC e0004e286c50364f134c951754c34e815489ead0
1 file changed +29
http-fetch.c
+29
@@ -100,6 +100,8 @@ static char *ssl_key = NULL;
100 static char *ssl_capath = NULL;
101 #endif
102 static char *ssl_cainfo = NULL;
103 +static long curl_low_speed_limit = -1;
104 +static long curl_low_speed_time = -1;
105
106 struct buffer
107 {
@@ -158,6 +160,17 @@ static int http_options(const char *var, const char *value)
160 }
161 #endif
162
163 + if (!strcmp("http.lowspeedlimit", var)) {
164 + if (curl_low_speed_limit == -1)
165 + curl_low_speed_limit = (long)git_config_int(var, value);
166 + return 0;
167 + }
168 + if (!strcmp("http.lowspeedtime", var)) {
169 + if (curl_low_speed_time == -1)
170 + curl_low_speed_time = (long)git_config_int(var, value);
171 + return 0;
172 + }
173 +
174 /* Fall back on the default ones */
175 return git_default_config(var, value);
176 }
@@ -246,6 +259,13 @@ static CURL* get_curl_handle(void)
259 curl_easy_setopt(result, CURLOPT_CAINFO, ssl_cainfo);
260 curl_easy_setopt(result, CURLOPT_FAILONERROR, 1);
261
262 + if (curl_low_speed_limit > 0 && curl_low_speed_time > 0) {
263 + curl_easy_setopt(result, CURLOPT_LOW_SPEED_LIMIT,
264 + curl_low_speed_limit);
265 + curl_easy_setopt(result, CURLOPT_LOW_SPEED_TIME,
266 + curl_low_speed_time);
267 + }
268 +
269 return result;
270 }
271
@@ -1177,6 +1197,8 @@ int main(int argc, char **argv)
1197 char *url;
1198 int arg = 1;
1199 struct active_request_slot *slot;
1200 + char *low_speed_limit;
1201 + char *low_speed_time;
1202
1203 while (arg < argc && argv[arg][0] == '-') {
1204 if (argv[arg][1] == 't') {
@@ -1232,6 +1254,13 @@ int main(int argc, char **argv)
1254 #endif
1255 ssl_cainfo = getenv("GIT_SSL_CAINFO");
1256
1257 + low_speed_limit = getenv("GIT_HTTP_LOW_SPEED_LIMIT");
1258 + if (low_speed_limit != NULL)
1259 + curl_low_speed_limit = strtol(low_speed_limit, NULL, 10);
1260 + low_speed_time = getenv("GIT_HTTP_LOW_SPEED_TIME");
1261 + if (low_speed_time != NULL)
1262 + curl_low_speed_time = strtol(low_speed_time, NULL, 10);
1263 +
1264 git_config(http_options);
1265
1266 if (curl_ssl_verify == -1)