diff mbox series

[1/7] channel_curl: Map response code for file:// protocol

Message ID 20220602091147.53323-1-christian.storm@siemens.com
State Accepted
Delegated to: Stefano Babic
Headers show
Series [1/7] channel_curl: Map response code for file:// protocol | expand

Commit Message

Storm, Christian June 2, 2022, 9:11 a.m. UTC
When using the file:// protocol with curl, there's naturally no
HTTP response code. Hence, map it to success to not fail the update.

Signed-off-by: Christian Storm <christian.storm@siemens.com>
---
 corelib/channel_curl.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Stefano Babic June 10, 2022, 9:12 a.m. UTC | #1
Hi Christian,

On 02.06.22 11:11, Christian Storm wrote:
> When using the file:// protocol with curl, there's naturally no
> HTTP response code. Hence, map it to success to not fail the update.
> 
> Signed-off-by: Christian Storm <christian.storm@siemens.com>
> ---
>   corelib/channel_curl.c | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c
> index 87a104a..1426390 100644
> --- a/corelib/channel_curl.c
> +++ b/corelib/channel_curl.c
> @@ -299,6 +299,7 @@ char *channel_get_redirect_url(channel_t *this)
>   channel_op_res_t channel_map_http_code(channel_t *this, long *http_response_code)
>   {
>   	char *url = NULL;
> +	long protocol;
>   	channel_curl_t *channel_curl = this->priv;
>   	CURLcode curlrc =
>   	    curl_easy_getinfo(channel_curl->handle, CURLINFO_RESPONSE_CODE,
> @@ -312,7 +313,12 @@ channel_op_res_t channel_map_http_code(channel_t *this, long *http_response_code
>   		return CHANNEL_EINIT;
>   	}
>   	switch (*http_response_code) {
> -	case 0:   /* libcURL: no server response code has been received yet */
> +	case 0:   /* libcURL: no server response code has been received yet or file:// protocol */
> +		curlrc = curl_easy_getinfo(channel_curl->handle, CURLINFO_PROTOCOL,
> +					   &protocol);
> +		if (curlrc == CURLE_OK && protocol == CURLPROTO_FILE) {
> +			return CHANNEL_OK;
> +		}
>   		DEBUG("No HTTP response code has been received yet!");
>   		return CHANNEL_EBADMSG;
>   	case 401: /* Unauthorized. The request requires user authentication. */


Reviewd-by: Stefano Babic <sbabic@denx.de>

This is orthogonal to the rest, and I will apply it directly.

Best regards,
Stefano
diff mbox series

Patch

diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c
index 87a104a..1426390 100644
--- a/corelib/channel_curl.c
+++ b/corelib/channel_curl.c
@@ -299,6 +299,7 @@  char *channel_get_redirect_url(channel_t *this)
 channel_op_res_t channel_map_http_code(channel_t *this, long *http_response_code)
 {
 	char *url = NULL;
+	long protocol;
 	channel_curl_t *channel_curl = this->priv;
 	CURLcode curlrc =
 	    curl_easy_getinfo(channel_curl->handle, CURLINFO_RESPONSE_CODE,
@@ -312,7 +313,12 @@  channel_op_res_t channel_map_http_code(channel_t *this, long *http_response_code
 		return CHANNEL_EINIT;
 	}
 	switch (*http_response_code) {
-	case 0:   /* libcURL: no server response code has been received yet */
+	case 0:   /* libcURL: no server response code has been received yet or file:// protocol */
+		curlrc = curl_easy_getinfo(channel_curl->handle, CURLINFO_PROTOCOL,
+					   &protocol);
+		if (curlrc == CURLE_OK && protocol == CURLPROTO_FILE) {
+			return CHANNEL_OK;
+		}
 		DEBUG("No HTTP response code has been received yet!");
 		return CHANNEL_EBADMSG;
 	case 401: /* Unauthorized. The request requires user authentication. */