[vlc-commits] http: add flag for chunked encoding
Rémi Denis-Courmont
git at videolan.org
Sun Oct 4 09:54:30 CEST 2020
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Oct 4 10:41:07 2020 +0300| [6144eebebffe66977afc89be7010ab6b9328b4c9] | committer: Rémi Denis-Courmont
http: add flag for chunked encoding
When formatting a message to HTTP 1.1, chunked encoding is often
necessary. However if the input message structure is not tied to any
specific HTTP version, it cannot contain the chunked encoding, which
will only be added when formatting.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=6144eebebffe66977afc89be7010ab6b9328b4c9
---
modules/access/http/h1conn.c | 2 +-
modules/access/http/message.c | 5 ++++-
modules/access/http/message.h | 3 ++-
modules/access/http/message_test.c | 2 +-
4 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/modules/access/http/h1conn.c b/modules/access/http/h1conn.c
index 2fdd26614e..2b5b508a8f 100644
--- a/modules/access/http/h1conn.c
+++ b/modules/access/http/h1conn.c
@@ -150,7 +150,7 @@ static struct vlc_http_stream *vlc_h1_stream_open(struct vlc_http_conn *c,
if (conn->active || conn->conn.tls == NULL)
return NULL;
- char *payload = vlc_http_msg_format(req, &len, conn->proxy);
+ char *payload = vlc_http_msg_format(req, &len, conn->proxy, false);
if (unlikely(payload == NULL))
return NULL;
diff --git a/modules/access/http/message.c b/modules/access/http/message.c
index 9ea1566196..232b340c44 100644
--- a/modules/access/http/message.c
+++ b/modules/access/http/message.c
@@ -296,7 +296,7 @@ block_t *vlc_http_msg_read(struct vlc_http_msg *m)
/* Serialization and deserialization */
char *vlc_http_msg_format(const struct vlc_http_msg *m, size_t *restrict lenp,
- bool proxied)
+ bool proxied, bool chunked)
{
struct vlc_memstream stream;
@@ -317,6 +317,9 @@ char *vlc_http_msg_format(const struct vlc_http_msg *m, size_t *restrict lenp,
vlc_memstream_printf(&stream, "%s: %s\r\n",
m->headers[i][0], m->headers[i][1]);
+ if (chunked)
+ vlc_memstream_puts(&stream, "Transfer-Encoding: chunked\r\n");
+
vlc_memstream_puts(&stream, "\r\n");
if (vlc_memstream_close(&stream))
diff --git a/modules/access/http/message.h b/modules/access/http/message.h
index 83835f265d..45e9b7c353 100644
--- a/modules/access/http/message.h
+++ b/modules/access/http/message.h
@@ -397,11 +397,12 @@ static inline void vlc_http_stream_close(struct vlc_http_stream *s, bool abort)
* [OUT]
* @param proxied whether the message is meant for sending to a proxy rather
* than an origin (only relevant for requests)
+ * @param chunked whether to append a chunked transfer encoding header line
* @return A heap-allocated nul-terminated string or *lenp bytes,
* or NULL on error
*/
char *vlc_http_msg_format(const struct vlc_http_msg *m, size_t *restrict lenp,
- bool proxied) VLC_USED;
+ bool proxied, bool chunked) VLC_USED;
/**
* Parses an HTTP 1.1 message header.
diff --git a/modules/access/http/message_test.c b/modules/access/http/message_test.c
index 6088e4f4ab..8f9f2633db 100644
--- a/modules/access/http/message_test.c
+++ b/modules/access/http/message_test.c
@@ -117,7 +117,7 @@ static void check_msg(struct vlc_http_msg *in,
cb(in);
- m1 = vlc_http_msg_format(in, &len, false);
+ m1 = vlc_http_msg_format(in, &len, false, true);
assert(m1 != NULL);
assert(strlen(m1) == len);
out = vlc_http_msg_headers(m1);
More information about the vlc-commits
mailing list