[vlc-commits] http: add proxy authentication

Rémi Denis-Courmont git at videolan.org
Sun Apr 3 17:42:11 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Apr  3 18:41:39 2016 +0300| [bb42e1705de3e43e7d8944869c350e34dae90c39] | committer: Rémi Denis-Courmont

http: add proxy authentication

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

 modules/access/http/tunnel.c |   21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/modules/access/http/tunnel.c b/modules/access/http/tunnel.c
index eb5ef3a..673f274 100644
--- a/modules/access/http/tunnel.c
+++ b/modules/access/http/tunnel.c
@@ -48,7 +48,9 @@ static char *vlc_http_authority(const char *host, unsigned port)
 
 static struct vlc_http_msg *vlc_http_tunnel_open(struct vlc_http_conn *conn,
                                                  const char *hostname,
-                                                 unsigned port)
+                                                 unsigned port,
+                                                 const char *username,
+                                                 const char *password)
 {
     char *authority = vlc_http_authority(hostname, port);
     if (authority == NULL)
@@ -62,6 +64,9 @@ static struct vlc_http_msg *vlc_http_tunnel_open(struct vlc_http_conn *conn,
 
     vlc_http_msg_add_header(req, "ALPN", "h2, http%%2F1.1");
     vlc_http_msg_add_agent(req, PACKAGE_NAME "/" PACKAGE_VERSION);
+    if (username != NULL)
+        vlc_http_msg_add_creds_basic(req, true, username,
+                                     (password != NULL) ? password : "");
 
     struct vlc_http_stream *stream = vlc_http_stream_open(conn, req);
 
@@ -151,16 +156,20 @@ vlc_tls_t *vlc_https_connect_proxy(vlc_tls_creds_t *creds,
     else
         sock = NULL;
 
-    vlc_UrlClean(&url);
-
     if (sock == NULL)
+    {
+        vlc_UrlClean(&url);
         return NULL;
+    }
 
     assert(!ptwo); /* HTTP/2 proxy not supported yet */
 
     struct vlc_tls *psock = malloc(sizeof (*psock));
     if (unlikely(psock == NULL))
+    {
+        vlc_UrlClean(&url);
         goto error;
+    }
 
     psock->obj = VLC_OBJECT(creds);
     psock->sys = sock;
@@ -176,10 +185,14 @@ vlc_tls_t *vlc_https_connect_proxy(vlc_tls_creds_t *creds,
     if (unlikely(conn == NULL))
     {
         vlc_tls_Close(psock);
+        vlc_UrlClean(&url);
         goto error;
     }
 
-    struct vlc_http_msg *resp = vlc_http_tunnel_open(conn, hostname, port);
+    struct vlc_http_msg *resp = vlc_http_tunnel_open(conn, hostname, port,
+                                                     url.psz_username,
+                                                     url.psz_password);
+    vlc_UrlClean(&url);
 
     /* TODO: reuse connection to HTTP/2 proxy */
     vlc_http_conn_release(conn); /* psock is destroyed there too */



More information about the vlc-commits mailing list