diff mbox series

[02/12] channel_curl: make followlink configurable

Message ID 20181002143357.9329-2-sbabic@denx.de
State Accepted
Headers show
Series None | expand

Commit Message

Stefano Babic Oct. 2, 2018, 2:33 p.m. UTC
In most cases, a HTTP redirect should be follow to get
the data to be retrieved. Some protocols require a logic
when a redirect is received, and the automatic logic inside
the libcurl library is not sufficient.

Ann a "nofollow" flag in the channel configuration data (inverted
logic to be compatible with current implementation) to allow to disable
the Curl option.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 corelib/channel_curl.c | 9 +++++++--
 include/channel_curl.h | 1 +
 2 files changed, 8 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c
index 574a3bc..805bbd4 100644
--- a/corelib/channel_curl.c
+++ b/corelib/channel_curl.c
@@ -386,8 +386,6 @@  channel_op_res_t channel_set_options(channel_t *this,
 			      channel_curl->header) != CURLE_OK) ||
 	    (curl_easy_setopt(channel_curl->handle, CURLOPT_MAXREDIRS, -1) !=
 	     CURLE_OK) ||
-	    (curl_easy_setopt(channel_curl->handle, CURLOPT_FOLLOWLOCATION, 1) !=
-	     CURLE_OK) ||
 	    (curl_easy_setopt(channel_curl->handle, CURLOPT_REDIR_PROTOCOLS,
 			      CURLPROTO_HTTP | CURLPROTO_HTTPS) != CURLE_OK) ||
 	    (curl_easy_setopt(channel_curl->handle,
@@ -403,6 +401,13 @@  channel_op_res_t channel_set_options(channel_t *this,
 		goto cleanup;
 	}
 
+	if ((!channel_data->nofollow) &&
+	    (curl_easy_setopt(channel_curl->handle, CURLOPT_FOLLOWLOCATION, 1) !=
+	     CURLE_OK)) {
+		result = CHANNEL_EINIT;
+		goto cleanup;
+	}
+
 	double percent = -INFINITY;
 	if ((curl_easy_setopt(channel_curl->handle, CURLOPT_PROGRESSFUNCTION,
 			      channel_callback_xferinfo_legacy) != CURLE_OK) ||
diff --git a/include/channel_curl.h b/include/channel_curl.h
index aa4875c..e8abc4c 100644
--- a/include/channel_curl.h
+++ b/include/channel_curl.h
@@ -58,6 +58,7 @@  typedef struct {
 	bool usessl;
 	bool strictssl;
 	bool nocheckanswer;
+	bool nofollow;
 	int (*checkdwl)(void);
 	struct swupdate_digest *dgst;
 	char sha1hash[SHA_DIGEST_LENGTH * 2 + 1];