http: create function to get curl allowed protocols
Move the creation of an allowed protocols whitelist to a helper function. This will be useful when we need to compute the set of allowed protocols differently for normal and redirect cases. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brandon Williams committed
Dec 14, 2016 at 14:39 UTC
aeae4db1747d891dc3aee6a74508c585c321cc49
1 file changed
+20
-11
http.c
+20
-11
@@ -489,10 +489,25 @@ static void set_curl_keepalive(CURL *c)
489
}
490
#endif
491
492
+static long get_curl_allowed_protocols(void)
493
+{
494
+ long allowed_protocols = 0;
495
+
496
+ if (is_transport_allowed("http"))
497
+ allowed_protocols |= CURLPROTO_HTTP;
498
+ if (is_transport_allowed("https"))
499
+ allowed_protocols |= CURLPROTO_HTTPS;
500
+ if (is_transport_allowed("ftp"))
501
+ allowed_protocols |= CURLPROTO_FTP;
502
+ if (is_transport_allowed("ftps"))
503
+ allowed_protocols |= CURLPROTO_FTPS;
504
+
505
+ return allowed_protocols;
506
+}
507
+
508
static CURL *get_curl_handle(void)
509
{
510
CURL *result = curl_easy_init();
495
- long allowed_protocols = 0;
511
512
if (!result)
513
die("curl_easy_init failed");
@@ -572,16 +587,10 @@ static CURL *get_curl_handle(void)
587
curl_easy_setopt(result, CURLOPT_POST301, 1);
588
#endif
589
#if LIBCURL_VERSION_NUM >= 0x071304
575
- if (is_transport_allowed("http"))
576
- allowed_protocols |= CURLPROTO_HTTP;
577
- if (is_transport_allowed("https"))
578
- allowed_protocols |= CURLPROTO_HTTPS;
579
- if (is_transport_allowed("ftp"))
580
- allowed_protocols |= CURLPROTO_FTP;
581
- if (is_transport_allowed("ftps"))
582
- allowed_protocols |= CURLPROTO_FTPS;
583
- curl_easy_setopt(result, CURLOPT_REDIR_PROTOCOLS, allowed_protocols);
584
- curl_easy_setopt(result, CURLOPT_PROTOCOLS, allowed_protocols);
590
+ curl_easy_setopt(result, CURLOPT_REDIR_PROTOCOLS,
591
+ get_curl_allowed_protocols());
592
+ curl_easy_setopt(result, CURLOPT_PROTOCOLS,
593
+ get_curl_allowed_protocols());
594
#else
595
warning("protocol restrictions not applied to curl redirects because\n"
596
"your curl version is too old (>= 7.19.4)");