From 741b6853b98c052e78018883bbd60a4395d11be6 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 18 Jun 2023 00:37:22 +0200 Subject: [PATCH] examples: make use of CURLOPT_(REDIR_|)PROTOCOLS_STR To show how to use them Closes #11334 --- docs/examples/crawler.c | 2 ++ docs/examples/urlapi.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/docs/examples/crawler.c b/docs/examples/crawler.c index aadfe2fb06..e2b58127d2 100644 --- a/docs/examples/crawler.c +++ b/docs/examples/crawler.c @@ -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); diff --git a/docs/examples/urlapi.c b/docs/examples/urlapi.c index f266365db5..2ed78eb11f 100644 --- a/docs/examples/urlapi.c +++ b/docs/examples/urlapi.c @@ -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) -- 2.47.3