[vlc-commits] http: add parameter for proxied requests

Rémi Denis-Courmont git at videolan.org
Tue Jan 5 22:57:50 CET 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Jan  5 19:18:18 2016 +0200| [4adb5fc7fe536414ee0c19679b9a4912e95fe7b0] | committer: Rémi Denis-Courmont

http: add parameter for proxied requests

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

 modules/access/http/conn.h         |    2 +-
 modules/access/http/connmgr.c      |    4 ++--
 modules/access/http/h1conn.c       |    6 ++++--
 modules/access/http/h1conn_test.c  |    2 +-
 modules/access/http/message.c      |   16 ++++++++++++++--
 modules/access/http/message.h      |    3 ++-
 modules/access/http/message_test.c |    2 +-
 modules/access/http/tunnel.c       |    4 ++--
 8 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/modules/access/http/conn.h b/modules/access/http/conn.h
index 75fdea0..0b9aa8c 100644
--- a/modules/access/http/conn.h
+++ b/modules/access/http/conn.h
@@ -47,7 +47,7 @@ static inline void vlc_http_conn_release(struct vlc_http_conn *conn)
     conn->cbs->release(conn);
 }
 
-struct vlc_http_conn *vlc_h1_conn_create(struct vlc_tls *);
+struct vlc_http_conn *vlc_h1_conn_create(struct vlc_tls *, bool proxy);
 struct vlc_http_conn *vlc_h2_conn_create(struct vlc_tls *);
 
 struct vlc_http_stream *vlc_chunked_open(struct vlc_http_stream *,
diff --git a/modules/access/http/connmgr.c b/modules/access/http/connmgr.c
index 59af37f..704c5d4 100644
--- a/modules/access/http/connmgr.c
+++ b/modules/access/http/connmgr.c
@@ -246,7 +246,7 @@ static struct vlc_http_msg *vlc_https_request(struct vlc_http_mgr *mgr,
     if (http2)
         conn = vlc_h2_conn_create(tls);
     else
-        conn = vlc_h1_conn_create(tls);
+        conn = vlc_h1_conn_create(tls, false);
 
     if (unlikely(conn == NULL))
     {
@@ -279,7 +279,7 @@ static struct vlc_http_msg *vlc_http_request(struct vlc_http_mgr *mgr,
     if (mgr->use_h2c)
         conn = vlc_h2_conn_create(tls);
     else
-        conn = vlc_h1_conn_create(tls);
+        conn = vlc_h1_conn_create(tls, false);
 
     if (unlikely(conn == NULL))
     {
diff --git a/modules/access/http/h1conn.c b/modules/access/http/h1conn.c
index 6d1e7fda..9801d36 100644
--- a/modules/access/http/h1conn.c
+++ b/modules/access/http/h1conn.c
@@ -114,6 +114,7 @@ struct vlc_h1_conn
     bool connection_close;
     bool active;
     bool released;
+    bool proxy;
 };
 
 #define CO(conn) ((conn)->conn.tls->obj)
@@ -149,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);
+    char *payload = vlc_http_msg_format(req, &len, conn->proxy);
     if (unlikely(payload == NULL))
         return NULL;
 
@@ -312,7 +313,7 @@ static const struct vlc_http_conn_cbs vlc_h1_conn_callbacks =
     vlc_h1_conn_release,
 };
 
-struct vlc_http_conn *vlc_h1_conn_create(vlc_tls_t *tls)
+struct vlc_http_conn *vlc_h1_conn_create(vlc_tls_t *tls, bool proxy)
 {
     struct vlc_h1_conn *conn = malloc(sizeof (*conn));
     if (unlikely(conn == NULL))
@@ -323,6 +324,7 @@ struct vlc_http_conn *vlc_h1_conn_create(vlc_tls_t *tls)
     conn->stream.cbs = &vlc_h1_stream_callbacks;
     conn->active = false;
     conn->released = false;
+    conn->proxy = proxy;
 
     return &conn->conn;
 }
diff --git a/modules/access/http/h1conn_test.c b/modules/access/http/h1conn_test.c
index e9c1e80..773d64a 100644
--- a/modules/access/http/h1conn_test.c
+++ b/modules/access/http/h1conn_test.c
@@ -55,7 +55,7 @@ static void conn_create(void)
 
     external_fd = fds[0];
 
-    conn = vlc_h1_conn_create(tls);
+    conn = vlc_h1_conn_create(tls, false);
     assert(conn != NULL);
 }
 
diff --git a/modules/access/http/message.c b/modules/access/http/message.c
index fb0693b..fb7a866 100644
--- a/modules/access/http/message.c
+++ b/modules/access/http/message.c
@@ -287,7 +287,8 @@ 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)
+char *vlc_http_msg_format(const struct vlc_http_msg *m, size_t *restrict lenp,
+                          bool proxied)
 {
     size_t len;
 
@@ -297,6 +298,12 @@ char *vlc_http_msg_format(const struct vlc_http_msg *m, size_t *restrict lenp)
         len += strlen(m->method);
         len += strlen(m->path ? m->path : m->authority);
         len += strlen(m->authority);
+
+        if (proxied)
+        {
+            assert(m->scheme != NULL && m->path != NULL);
+            len += strlen(m->scheme) + 3 + strlen(m->authority);
+        }
     }
     else
         len = sizeof ("HTTP/1.1 123 .\r\n\r\n");
@@ -311,8 +318,13 @@ char *vlc_http_msg_format(const struct vlc_http_msg *m, size_t *restrict lenp)
     len = 0;
 
     if (m->status < 0)
-        len += sprintf(buf, "%s %s HTTP/1.1\r\nHost: %s\r\n", m->method,
+    {
+        len += sprintf(buf, "%s ", m->method);
+        if (proxied)
+            len += sprintf(buf + len, "%s://%s", m->scheme, m->authority);
+        len += sprintf(buf + len, "%s HTTP/1.1\r\nHost: %s\r\n",
                        m->path ? m->path : m->authority, m->authority);
+    }
     else
         len += sprintf(buf, "HTTP/1.1 %03hd .\r\n", m->status);
 
diff --git a/modules/access/http/message.h b/modules/access/http/message.h
index 10f3f47..eebe7f7 100644
--- a/modules/access/http/message.h
+++ b/modules/access/http/message.h
@@ -252,7 +252,8 @@ static inline void vlc_http_stream_close(struct vlc_http_stream *s, bool abort)
     s->cbs->close(s, abort);
 }
 
-char *vlc_http_msg_format(const struct vlc_http_msg *m, size_t *) VLC_USED;
+char *vlc_http_msg_format(const struct vlc_http_msg *m, size_t *restrict lenp,
+                          bool proxied) VLC_USED;
 struct vlc_http_msg *vlc_http_msg_headers(const char *msg) VLC_USED;
 
 struct vlc_h2_frame;
diff --git a/modules/access/http/message_test.c b/modules/access/http/message_test.c
index 5e449e1..1677dba 100644
--- a/modules/access/http/message_test.c
+++ b/modules/access/http/message_test.c
@@ -115,7 +115,7 @@ static void check_msg(struct vlc_http_msg *in,
 
     cb(in);
 
-    m1 = vlc_http_msg_format(in, &len);
+    m1 = vlc_http_msg_format(in, &len, false);
     assert(m1 != NULL);
     assert(strlen(m1) == len);
     out = vlc_http_msg_headers(m1);
diff --git a/modules/access/http/tunnel.c b/modules/access/http/tunnel.c
index a5f9e16..b26efbd 100644
--- a/modules/access/http/tunnel.c
+++ b/modules/access/http/tunnel.c
@@ -140,8 +140,8 @@ vlc_tls_t *vlc_https_connect_proxy(vlc_tls_creds_t *creds,
     if (session == NULL)
         return NULL;
 
-    struct vlc_http_conn *conn = (ptwo ? vlc_h2_conn_create
-                                       : vlc_h1_conn_create)(session);
+    struct vlc_http_conn *conn = ptwo ? vlc_h2_conn_create(session)
+                                      : vlc_h1_conn_create(session, false);
     if (unlikely(conn == NULL))
     {
         vlc_tls_Close(session);



More information about the vlc-commits mailing list