[vlc-commits] httpd: simplify/fix connection closing

Rémi Denis-Courmont git at videolan.org
Sun Oct 8 17:28:24 CEST 2017


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Oct  8 18:22:26 2017 +0300| [c711cf7ccfe387e343224f64c2af8120796a138a] | committer: Rémi Denis-Courmont

httpd: simplify/fix connection closing

Close the connection if request is HTTP/1.0 or if the connection header
line in the response exists and is "close". This works because close is
the only that ever gets set as response so far; it wouldn't work if any
other token were emitted by the server.

Note: the RTSP server and the Lua art callback do not handle connection
close correctly still.

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

 src/network/httpd.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/src/network/httpd.c b/src/network/httpd.c
index 9bb827eb17..629e762c47 100644
--- a/src/network/httpd.c
+++ b/src/network/httpd.c
@@ -1892,23 +1892,22 @@ static void httpdLoop(httpd_host_t *host)
 
             case HTTPD_CLIENT_SEND_DONE:
                 if (!cl->b_stream_mode || cl->answer.i_body_offset == 0) {
-                    const char *psz_connection = httpd_MsgGet(&cl->answer, "Connection");
-                    const char *psz_query = httpd_MsgGet(&cl->query, "Connection");
-                    bool b_connection = false;
-                    bool b_query = false;
+                    bool do_close = false;
 
                     cl->url = NULL;
-                    if (psz_connection) {
-                        b_connection = (strcasecmp(psz_connection, "Close") == 0);
-                    }
 
-                    if (psz_query)
-                        b_query = (strcasecmp(psz_query, "Close") == 0);
+                    if (cl->query.i_proto != HTTPD_PROTO_HTTP
+                     || cl->query.i_version > 0)
+                    {
+                        const char *psz_connection = httpd_MsgGet(&cl->answer,
+                                                                 "Connection");
+                        if (psz_connection != NULL)
+                            do_close = !strcasecmp(psz_connection, "close");
+                    }
+                    else
+                        do_close = true;
 
-                    if (((cl->query.i_proto == HTTPD_PROTO_HTTP) &&
-                                (cl->query.i_version == 1 && !b_connection)) ||
-                            ((cl->query.i_proto == HTTPD_PROTO_RTSP) &&
-                              !b_query && !b_connection)) {
+                    if (!do_close) {
                         httpd_MsgClean(&cl->query);
                         httpd_MsgInit(&cl->query);
 



More information about the vlc-commits mailing list