]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
examples: make use of CURLOPT_(REDIR_|)PROTOCOLS_STR
authorDaniel Stenberg <daniel@haxx.se>
Sat, 17 Jun 2023 22:37:22 +0000 (00:37 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Sun, 18 Jun 2023 09:09:13 +0000 (11:09 +0200)
To show how to use them

Closes #11334

docs/examples/crawler.c
docs/examples/urlapi.c

index aadfe2fb0624dcd4a8eac858a5f22f863f768410..e2b58127d2a12232264d298fdd43bdccb7fb2f3a 100644 (file)
@@ -95,6 +95,8 @@ CURL *make_handle(char *url)
   curl_easy_setopt(handle, CURLOPT_ACCEPT_ENCODING, "");
   curl_easy_setopt(handle, CURLOPT_TIMEOUT, 5L);
   curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1L);
+  /* only allow redirects to HTTP and HTTPS URLs */
+  curl_easy_setopt(handle, CURLOPT_REDIR_PROTOCOLS_STR, "http,https");
   curl_easy_setopt(handle, CURLOPT_AUTOREFERER, 1L);
   curl_easy_setopt(handle, CURLOPT_MAXREDIRS, 10L);
   curl_easy_setopt(handle, CURLOPT_CONNECTTIMEOUT, 2L);
index f266365db55ea6cc2631b0b9edeb87c172c86590..2ed78eb11fc60ee3ac295b4d06eef378b1c19443 100644 (file)
@@ -58,6 +58,9 @@ int main(void)
     curl_easy_setopt(curl, CURLOPT_CURLU, urlp);
     curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
 
+    /* only allow HTTP, TFTP and SFTP */
+    curl_easy_setopt(curl, CURLOPT_PROTOCOLS_STR, "http,tftp,sftp");
+
     res = curl_easy_perform(curl);
     /* Check for errors */
     if(res != CURLE_OK)