[vlc-commits] http: add --http2 to force HTTP/2

Rémi Denis-Courmont git at videolan.org
Sun Dec 13 18:08:30 CET 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Dec 13 19:07:13 2015 +0200| [99ce71250580070a4ed091e49cde3d2c7138ad58] | committer: Rémi Denis-Courmont

http: add --http2 to force HTTP/2

This is currently and transitionally used to test HTTP/2 over TLS.
Eventually, this should be done automatically.

Going forward, this will either be removed or used without TLS.

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

 modules/access/http.c |   32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/modules/access/http.c b/modules/access/http.c
index 3cbe7f2..bd4f5b5 100644
--- a/modules/access/http.c
+++ b/modules/access/http.c
@@ -117,6 +117,8 @@ vlc_module_begin ()
         change_safe()
     add_bool( "http-forward-cookies", true, FORWARD_COOKIES_TEXT,
               FORWARD_COOKIES_LONGTEXT, true )
+    add_bool( "http2", false, N_("HTTP 2.0"),
+              N_("Negotiate HTTP version 2.0"), true )
     /* 'itpc' = iTunes Podcast */
     add_shortcut( "http", "https", "unsv", "itpc", "icyx" )
     set_callbacks( Open, Close )
@@ -992,19 +994,20 @@ static int Connect( access_t *p_access, uint64_t i_tell )
     /* Initialize TLS/SSL session */
     if( p_sys->p_creds != NULL )
     {
+        bool http2 = var_InheritBool( p_access, "http2" );
+
+        if( (p_sys->b_proxy || http2) && p_sys->i_version == 0 )
+        {   /* ALPN and CONNECT are not compatible with HTTP/1.0 */
+            Disconnect( p_access );
+            return -1;
+        }
+
         /* CONNECT to establish TLS tunnel through HTTP proxy */
         if( p_sys->b_proxy )
         {
             char *psz;
             unsigned i_status;
 
-            if( p_sys->i_version == 0 )
-            {
-                /* CONNECT is not in HTTP/1.0 */
-                Disconnect( p_access );
-                return -1;
-            }
-
             WriteHeaders( p_access,
                           "CONNECT %s:%d HTTP/1.1\r\nHost: %s:%d\r\n\r\n",
                           p_sys->url.psz_host, p_sys->url.i_port,
@@ -1054,17 +1057,28 @@ static int Connect( access_t *p_access, uint64_t i_tell )
         }
 
         /* TLS/SSL handshake */
-        const char *alpn[] = { "http/1.1", NULL };
+        const char *alpn[3] = { "h2", "http/1.1", NULL };
+        char *alp;
 
         p_sys->p_tls = vlc_tls_ClientSessionCreate( p_sys->p_creds, p_sys->fd,
                 p_sys->url.psz_host, "https",
-                p_sys->i_version ? alpn : NULL, NULL );
+                p_sys->i_version ? (alpn + !http2) : NULL, &alp );
         if( p_sys->p_tls == NULL )
         {
             msg_Err( p_access, "cannot establish HTTP/TLS session" );
             Disconnect( p_access );
             return -1;
         }
+
+        http2 = alp != NULL && !strcmp("h2", alp);
+        free( alp );
+
+        if( http2 )
+        {
+            msg_Dbg( p_access, "handing off to HTTP2 plugin" );
+            Disconnect( p_access );
+            return -1;
+        }
     }
 
     return Request( p_access, i_tell ) ? -2 : 0;



More information about the vlc-commits mailing list