[vlc-devel] [PATCH] http: handle 302 relative redirections

Francois Cartegnie fcvlcdev at free.fr
Mon Dec 2 12:23:11 CET 2013


While playing with ASF DRM, I experienced that the 
http access doesn't follow any relative 302 redirects from
MS shitty servers.
(302 from http//foo/bar/ to welcome.asp/en/)

Probably out-of-spec, but in use, I'd suggest handling it.

Francois

---
 modules/access/http.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/modules/access/http.c b/modules/access/http.c
index 3908fb7..1db1cc5 100644
--- a/modules/access/http.c
+++ b/modules/access/http.c
@@ -488,6 +488,31 @@ connect:
             goto error;
         }
 
+        /* Test if we have a relative, appending, redirection */
+        if ( *p_sys->psz_location != '/' && !strstr( p_sys->psz_location, "://" ) )
+        {
+            size_t i_access_length = strlen( p_access->psz_access );
+            size_t i_current_length = strlen( p_access->psz_location );
+            size_t i_relative_length = strlen( p_sys->psz_location );
+            char *psz_temp = malloc( i_access_length + 3 + i_current_length +
+                                     i_relative_length + 1 );
+            if ( !psz_temp )
+                goto error;
+            char *psz = psz_temp;
+            memcpy( psz, p_access->psz_access, i_access_length );
+            psz += i_access_length;
+            memcpy( psz, "://", 3 );
+            psz += 3;
+            memcpy( psz, p_access->psz_location, i_current_length );
+            psz += i_current_length;
+            memcpy( psz, p_sys->psz_location, i_relative_length );
+            psz += i_relative_length;
+            *psz = 0;
+            free( p_sys->psz_location );
+            p_sys->psz_location = psz_temp;
+            msg_Dbg( p_access, "redirection after relative fix to %s", p_sys->psz_location );
+        }
+
         const char *psz_protocol;
         if( !strncmp( p_sys->psz_location, "http://", 7 ) )
             psz_protocol = "http";
-- 
1.8.3.1




More information about the vlc-devel mailing list