]> git.sesse.net Git - vlc/blobdiff - modules/access/http.c
No need to send Connection: close or Connection: Keep-Alive.
[vlc] / modules / access / http.c
index cfb207de76f58963f2bdb5d3f2010d073474c06e..a4bc00e323de33253eee66a4dca3e3862730c681 100644 (file)
@@ -52,6 +52,9 @@
 
 #include <assert.h>
 
+#ifdef HAVE_PROXY_H
+#    include "proxy.h"
+#endif
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
@@ -315,7 +318,40 @@ static int OpenWithCookies( vlc_object_t *p_this, vlc_array_t *cookies )
         vlc_UrlParse( &p_sys->proxy, psz, 0 );
         free( psz );
     }
-#ifdef HAVE_GETENV
+#ifdef HAVE_PROXY_H
+    else
+    {
+        pxProxyFactory *pf = px_proxy_factory_new();
+        if (pf)
+        {
+            char *buf;
+            int i;
+            i=asprintf(&buf, "%s://%s", p_access->psz_access, p_access->psz_path);
+            if (i >= 0)
+            {
+                msg_Dbg(p_access, "asking libproxy about url '%s'", buf);
+                char **proxies = px_proxy_factory_get_proxies(pf, buf);
+                if (proxies[0])
+                {
+                    msg_Dbg(p_access, "libproxy suggest to use '%s'", proxies[0]);
+                    if(strcmp(proxies[0],"direct://") != 0) 
+                    {
+                        p_sys->b_proxy = true;
+                        vlc_UrlParse( &p_sys->proxy, proxies[0], 0);
+                    }
+                }
+                for(i=0;proxies[i];i++) free(proxies[i]);
+                free(proxies);
+                free(buf);
+            }
+            px_proxy_factory_free(pf);
+        }
+        else
+        {
+            msg_Err(p_access, "Allocating memory for libproxy failed");
+        }
+    }
+#elif HAVE_GETENV
     else
     {
         psz = getenv( "http_proxy" );
@@ -845,6 +881,17 @@ static int Seek( access_t *p_access, int64_t i_pos )
 
     Disconnect( p_access );
 
+    if( p_access->info.i_size
+     && (uint64_t)i_pos >= (uint64_t)p_access->info.i_size ) {
+        msg_Err( p_access, "seek to far" );
+        int retval = Seek( p_access, p_access->info.i_size - 1 );
+        if( retval == VLC_SUCCESS ) {
+            uint8_t p_buffer[2];
+            Read( p_access, p_buffer, 1);
+            p_access->info.b_eof  = false;
+        }
+        return retval;
+    }
     if( Connect( p_access, i_pos ) )
     {
         msg_Err( p_access, "seek failed" );
@@ -1105,7 +1152,7 @@ static int Request( access_t *p_access, int64_t i_tell )
     if( p_sys->i_version == 1 )
     {
         net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs,
-                    "Range: bytes=%"PRId64"-\r\n", i_tell );
+                    "Range: bytes=%"PRIu64"-\r\n", i_tell );
     }
 
     /* Cookies */
@@ -1146,17 +1193,6 @@ static int Request( access_t *p_access, int64_t i_tell )
     net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs, "Icy-MetaData: 1\r\n" );
 
 
-    if( p_sys->b_continuous )
-    {
-        net_Printf( VLC_OBJECT( p_access ), p_sys->fd, pvs,
-                    "Connection: Keep-Alive\r\n" );
-    }
-    else if( p_sys->i_version == 1 )
-    {
-        net_Printf( VLC_OBJECT( p_access ), p_sys->fd, pvs,
-                    "Connection: Close\r\n");
-    }
-
     if( net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs, "\r\n" ) < 0 )
     {
         msg_Err( p_access, "failed to send request" );
@@ -1409,6 +1445,9 @@ static int Request( access_t *p_access, int64_t i_tell )
 
         free( psz );
     }
+    if(p_sys->i_remaining == 0 && (p_access->info.i_size == -1 || p_access->info.i_size == i_tell)) {
+        Disconnect( p_access );
+    }
     return VLC_SUCCESS;
 
 error: