|
8 | 8 | #include "credential.h" |
9 | 9 | #include "version.h" |
10 | 10 | #include "pkt-line.h" |
| 11 | +#include "transport.h" |
11 | 12 |
|
12 | 13 | int active_requests; |
13 | 14 | int http_is_verbose; |
@@ -303,6 +304,7 @@ static void set_curl_keepalive(CURL *c) |
303 | 304 | static CURL *get_curl_handle(void) |
304 | 305 | { |
305 | 306 | CURL *result = curl_easy_init(); |
| 307 | + long allowed_protocols = 0; |
306 | 308 |
|
307 | 309 | if (!result) |
308 | 310 | die("curl_easy_init failed"); |
@@ -350,11 +352,27 @@ static CURL *get_curl_handle(void) |
350 | 352 | } |
351 | 353 |
|
352 | 354 | curl_easy_setopt(result, CURLOPT_FOLLOWLOCATION, 1); |
| 355 | + curl_easy_setopt(result, CURLOPT_MAXREDIRS, 20); |
353 | 356 | #if LIBCURL_VERSION_NUM >= 0x071301 |
354 | 357 | curl_easy_setopt(result, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL); |
355 | 358 | #elif LIBCURL_VERSION_NUM >= 0x071101 |
356 | 359 | curl_easy_setopt(result, CURLOPT_POST301, 1); |
357 | 360 | #endif |
| 361 | +#if LIBCURL_VERSION_NUM >= 0x071304 |
| 362 | + if (is_transport_allowed("http")) |
| 363 | + allowed_protocols |= CURLPROTO_HTTP; |
| 364 | + if (is_transport_allowed("https")) |
| 365 | + allowed_protocols |= CURLPROTO_HTTPS; |
| 366 | + if (is_transport_allowed("ftp")) |
| 367 | + allowed_protocols |= CURLPROTO_FTP; |
| 368 | + if (is_transport_allowed("ftps")) |
| 369 | + allowed_protocols |= CURLPROTO_FTPS; |
| 370 | + curl_easy_setopt(result, CURLOPT_REDIR_PROTOCOLS, allowed_protocols); |
| 371 | +#else |
| 372 | + if (transport_restrict_protocols()) |
| 373 | + warning("protocol restrictions not applied to curl redirects because\n" |
| 374 | + "your curl version is too old (>= 7.19.4)"); |
| 375 | +#endif |
358 | 376 |
|
359 | 377 | if (getenv("GIT_CURL_VERBOSE")) |
360 | 378 | curl_easy_setopt(result, CURLOPT_VERBOSE, 1); |
|
0 commit comments