+ /* Initialize TLS/SSL session */
+ if( p_sys->b_ssl == VLC_TRUE )
+ {
+ /* CONNECT to establish TLS tunnel through HTTP proxy */
+ if( p_sys->b_proxy )
+ {
+ char *psz;
+ unsigned i_status = 0;
+
+ if( p_sys->i_version == 0 )
+ {
+ /* CONNECT is not in HTTP/1.0 */
+ Disconnect( p_access );
+ return -1;
+ }
+
+ net_Printf( VLC_OBJECT(p_access), p_sys->fd, NULL,
+ "CONNECT %s:%d HTTP/1.%d\r\nHost: %s:%d\r\n\r\n",
+ p_sys->url.psz_host, p_sys->url.i_port,
+ p_sys->i_version,
+ p_sys->url.psz_host, p_sys->url.i_port);
+
+ psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL );
+ if( psz == NULL )
+ {
+ msg_Err( p_access, "cannot establish HTTP/TLS tunnel" );
+ Disconnect( p_access );
+ return -1;
+ }
+
+ sscanf( psz, "HTTP/%*u.%*u %3u", &i_status );
+ free( psz );
+
+ if( ( i_status / 100 ) != 2 )
+ {
+ msg_Err( p_access, "HTTP/TLS tunnel through proxy denied" );
+ Disconnect( p_access );
+ return -1;
+ }
+
+ do
+ {
+ psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL );
+ if( psz == NULL )
+ {
+ msg_Err( p_access, "HTTP proxy connection failed" );
+ Disconnect( p_access );
+ return -1;
+ }
+
+ if( *psz == '\0' )
+ i_status = 0;
+
+ free( psz );
+ }
+ while( i_status );
+ }
+
+ /* TLS/SSL handshake */
+ p_sys->p_tls = tls_ClientCreate( VLC_OBJECT(p_access), p_sys->fd,
+ srv.psz_host );
+ if( p_sys->p_tls == NULL )
+ {
+ msg_Err( p_access, "cannot establish HTTP/TLS session" );
+ Disconnect( p_access );
+ return -1;
+ }
+ p_sys->p_vs = &p_sys->p_tls->sock;
+ }
+
+ return Request( p_access, i_tell ) ? -2 : 0;
+}
+
+
+static int Request( access_t *p_access, int64_t i_tell )
+{
+ access_sys_t *p_sys = p_access->p_sys;
+ char *psz ;
+ v_socket_t *pvs = p_sys->p_vs;
+