[vlc-commits] http: HTTP 1.1 chunk write function

Rémi Denis-Courmont git at videolan.org
Sun Oct 4 12:26:24 CEST 2020


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Oct  4 10:21:56 2020 +0300| [df7c12db4bba908c5d8cb8386bdfabd3728849bd] | committer: Rémi Denis-Courmont

http: HTTP 1.1 chunk write function

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=df7c12db4bba908c5d8cb8386bdfabd3728849bd
---

 modules/access/http/chunked.c | 24 ++++++++++++++++++++++++
 modules/access/http/conn.h    |  2 ++
 2 files changed, 26 insertions(+)

diff --git a/modules/access/http/chunked.c b/modules/access/http/chunked.c
index eb94299cae..c37fbe3dd4 100644
--- a/modules/access/http/chunked.c
+++ b/modules/access/http/chunked.c
@@ -36,6 +36,30 @@
 #include "message.h"
 #include "conn.h"
 
+ssize_t vlc_https_chunked_write(struct vlc_tls *tls, const void *base,
+                                size_t len, bool eos)
+{
+    if (len > 0)
+    {
+        char hdr[sizeof (size_t) * 2 + 3];
+        int hlen = snprintf(hdr, sizeof (hdr), "%zx\r\n", len);
+
+        /* TODO: use iovec */
+        if (vlc_tls_Write(tls, hdr, hlen) < hlen)
+            return -1;
+        if (vlc_tls_Write(tls, base, len) < (ssize_t)len)
+            return -1;
+    }
+
+    if (eos)
+    {
+        if (vlc_tls_Write(tls, "0\r\n", 3) < 3)
+            return -1;
+    }
+
+    return len;
+}
+
 struct vlc_chunked_stream
 {
     struct vlc_http_stream stream;
diff --git a/modules/access/http/conn.h b/modules/access/http/conn.h
index 9f3dbbbecf..ff390d054c 100644
--- a/modules/access/http/conn.h
+++ b/modules/access/http/conn.h
@@ -67,6 +67,8 @@ struct vlc_http_conn *vlc_h1_conn_create(void *ctx, struct vlc_tls *,
                                          bool proxy);
 struct vlc_http_stream *vlc_chunked_open(struct vlc_http_stream *,
                                          struct vlc_tls *);
+ssize_t vlc_https_chunked_write(struct vlc_tls *, const void *base, size_t len,
+                                bool eos);
 
 /**
  * Sends an HTTP/1.x request through a new connection.



More information about the vlc-commits mailing list