diff mbox series

[11/29] channel_curl: do not automatically add charset header

Message ID 20211011112156.44192-12-sbabic@denx.de
State Changes Requested
Headers show
Series DELTA Update | expand

Commit Message

Stefano Babic Oct. 11, 2021, 11:21 a.m. UTC
If Content-type is set to bytes / binaries, the charset has no meaning.
Just add it automatically in case of application/json and
application/text. It is still possible to add it in other case, but the
caller should add it to the list of headers.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 corelib/channel_curl.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff mbox series

Patch

diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c
index 5c88ef7..50d5cc8 100644
--- a/corelib/channel_curl.c
+++ b/corelib/channel_curl.c
@@ -522,6 +522,17 @@  static channel_op_res_t channel_set_content_type(channel_t *this,
 			result = CHANNEL_EINIT;
 		}
 	}
+	/*
+	 * Add default charset for application content
+	 */
+	if ((!strcmp(content, "application/json") || !strcmp(content, "application/text")) &&
+             (result == CHANNEL_OK)) {
+		if ((channel_curl->header = curl_slist_append(
+			channel_curl->header, "charsets: utf-8")) == NULL) {
+			ERROR("Set channel charset header failed.");
+			result = CHANNEL_EINIT;
+		}
+	}
 
 	return result;
 }