diff mbox series

[V2,14/36] channel_curl: do not automatically add charset header

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

Commit Message

Stefano Babic Nov. 14, 2021, 5:27 p.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 d1c2f5a..287f827 100644
--- a/corelib/channel_curl.c
+++ b/corelib/channel_curl.c
@@ -524,6 +524,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;
 }