[vlc-commits] http: add maanger flag for requests with payload

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


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Oct  4 17:02:29 2020 +0300| [eee7f9db593b2ab5094aeaed36f396000020c184] | committer: Rémi Denis-Courmont

http: add maanger flag for requests with payload

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

 modules/access/http/connmgr.c   | 25 ++++++++++++++-----------
 modules/access/http/connmgr.h   |  3 ++-
 modules/access/http/file_test.c |  3 ++-
 modules/access/http/resource.c  |  2 +-
 4 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/modules/access/http/connmgr.c b/modules/access/http/connmgr.c
index 7f16405536..ca734853fc 100644
--- a/modules/access/http/connmgr.c
+++ b/modules/access/http/connmgr.c
@@ -124,13 +124,14 @@ static void vlc_http_mgr_release(struct vlc_http_mgr *mgr,
 static
 struct vlc_http_msg *vlc_http_mgr_reuse(struct vlc_http_mgr *mgr,
                                         const char *host, unsigned port,
-                                        const struct vlc_http_msg *req)
+                                        const struct vlc_http_msg *req,
+                                        bool payload)
 {
     struct vlc_http_conn *conn = vlc_http_mgr_find(mgr, host, port);
     if (conn == NULL)
         return NULL;
 
-    struct vlc_http_stream *stream = vlc_http_stream_open(conn, req, false);
+    struct vlc_http_stream *stream = vlc_http_stream_open(conn, req, payload);
     if (stream != NULL)
     {
         struct vlc_http_msg *m = vlc_http_msg_get_initial(stream);
@@ -145,7 +146,7 @@ struct vlc_http_msg *vlc_http_mgr_reuse(struct vlc_http_mgr *mgr,
 static struct vlc_http_msg *vlc_https_request(struct vlc_http_mgr *mgr,
                                               const char *host, unsigned port,
                                               const struct vlc_http_msg *req,
-                                              bool idempotent)
+                                              bool idempotent, bool payload)
 {
     vlc_tls_t *tls;
     bool http2 = true;
@@ -166,7 +167,8 @@ static struct vlc_http_msg *vlc_https_request(struct vlc_http_mgr *mgr,
          * the nonidempotent request was processed if the connection fails
          * before the response is received.
          */
-        struct vlc_http_msg *resp = vlc_http_mgr_reuse(mgr, host, port, req);
+        struct vlc_http_msg *resp = vlc_http_mgr_reuse(mgr, host, port, req,
+                                                       payload);
         if (resp != NULL)
             return resp; /* existing connection reused */
     }
@@ -208,20 +210,21 @@ static struct vlc_http_msg *vlc_https_request(struct vlc_http_mgr *mgr,
         vlc_http_mgr_release(mgr, mgr->conn);
 
     mgr->conn = conn;
-    return vlc_http_mgr_reuse(mgr, host, port, req);
+    return vlc_http_mgr_reuse(mgr, host, port, req, payload);
 }
 
 static struct vlc_http_msg *vlc_http_request(struct vlc_http_mgr *mgr,
                                              const char *host, unsigned port,
                                              const struct vlc_http_msg *req,
-                                             bool idempotent)
+                                             bool idempotent, bool payload)
 {
     if (mgr->creds != NULL && mgr->conn != NULL)
         return NULL; /* switch from HTTPS to HTTP not implemented */
 
     if (idempotent)
     {
-        struct vlc_http_msg *resp = vlc_http_mgr_reuse(mgr, host, port, req);
+        struct vlc_http_msg *resp = vlc_http_mgr_reuse(mgr, host, port, req,
+                                                       payload);
         if (resp != NULL)
             return resp;
     }
@@ -240,7 +243,7 @@ static struct vlc_http_msg *vlc_http_request(struct vlc_http_mgr *mgr,
         if (url.psz_host != NULL)
             stream = vlc_h1_request(mgr->logger, url.psz_host,
                                     url.i_port ? url.i_port : 80, true, req,
-                                    idempotent, false, &conn);
+                                    idempotent, payload, &conn);
         else
             stream = NULL;
 
@@ -248,7 +251,7 @@ static struct vlc_http_msg *vlc_http_request(struct vlc_http_mgr *mgr,
     }
     else
         stream = vlc_h1_request(mgr->logger, host, port ? port : 80, false,
-                                req, idempotent, false, &conn);
+                                req, idempotent, payload, &conn);
 
     if (stream == NULL)
         return NULL;
@@ -270,13 +273,13 @@ static struct vlc_http_msg *vlc_http_request(struct vlc_http_mgr *mgr,
 struct vlc_http_msg *vlc_http_mgr_request(struct vlc_http_mgr *mgr, bool https,
                                           const char *host, unsigned port,
                                           const struct vlc_http_msg *m,
-                                          bool idempotent)
+                                          bool idempotent, bool payload)
 {
     if (port && vlc_http_port_blocked(port))
         return NULL;
 
     return (https ? vlc_https_request : vlc_http_request)(mgr, host, port, m,
-                                                          idempotent);
+                                                          idempotent, payload);
 }
 
 struct vlc_http_cookie_jar_t *vlc_http_mgr_get_jar(struct vlc_http_mgr *mgr)
diff --git a/modules/access/http/connmgr.h b/modules/access/http/connmgr.h
index e853e1fde6..84bbb3c400 100644
--- a/modules/access/http/connmgr.h
+++ b/modules/access/http/connmgr.h
@@ -46,13 +46,14 @@ struct vlc_http_cookie_jar_t;
  * @param port TCP server port number, or 0 for the default port number
  * @param req HTTP request header to send
  * @param idempotent whether the request is idempotent
+ * @param payload whether the request will carry a payload
  *
  * @return The initial HTTP response header, or NULL in case of failure.
  */
 struct vlc_http_msg *vlc_http_mgr_request(struct vlc_http_mgr *mgr, bool https,
                                           const char *host, unsigned port,
                                           const struct vlc_http_msg *req,
-                                          bool idempotent);
+                                          bool idempotent, bool payload);
 
 struct vlc_http_cookie_jar_t *vlc_http_mgr_get_jar(struct vlc_http_mgr *);
 
diff --git a/modules/access/http/file_test.c b/modules/access/http/file_test.c
index fbe55d4689..b66e9e6240 100644
--- a/modules/access/http/file_test.c
+++ b/modules/access/http/file_test.c
@@ -337,7 +337,7 @@ static struct vlc_http_stream stream = { &stream_callbacks };
 struct vlc_http_msg *vlc_http_mgr_request(struct vlc_http_mgr *mgr, bool https,
                                           const char *host, unsigned port,
                                           const struct vlc_http_msg *req,
-                                          bool idempotent)
+                                          bool idempotent, bool payload)
 {
     const char *str;
     char *end;
@@ -347,6 +347,7 @@ struct vlc_http_msg *vlc_http_mgr_request(struct vlc_http_mgr *mgr, bool https,
     assert(!strcmp(host, "www.example.com"));
     assert(port == 8443);
     assert(idempotent);
+    assert(!payload);
 
     str = vlc_http_msg_get_method(req);
     assert(!strcmp(str, "GET"));
diff --git a/modules/access/http/resource.c b/modules/access/http/resource.c
index 2550146d00..e9669450e5 100644
--- a/modules/access/http/resource.c
+++ b/modules/access/http/resource.c
@@ -91,7 +91,7 @@ retry:
         return NULL;
 
     struct vlc_http_msg *resp = vlc_http_mgr_request(res->manager, res->secure,
-                                              res->host, res->port, req, true);
+                                       res->host, res->port, req, true, false);
     vlc_http_msg_destroy(req);
 
     resp = vlc_http_msg_get_final(resp);



More information about the vlc-commits mailing list