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

Francois Cartegnie fcvlcdev at free.fr
Mon Dec 2 12:34:36 CET 2013


Wrong branch;
That one handles both appending and /foo redirections.

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

diff --git a/modules/access/http.c b/modules/access/http.c
index 3908fb7..2fc1dab 100644
--- a/modules/access/http.c
+++ b/modules/access/http.c
@@ -488,6 +488,42 @@ connect:
             goto error;
         }
 
+        /* Test if we have a relative redirection */
+        if ( !strstr( p_sys->psz_location, "://" ) )
+        {
+            char *psz_temp;
+            size_t i_scheme_length = strlen( p_access->psz_access );
+            size_t i_append_length = strlen( p_sys->psz_location );
+            size_t i_current_length = 0;
+            if ( *p_sys->psz_location != '/' )
+            {
+                i_current_length = strlen( p_access->psz_location );
+            }
+            else
+            {
+                psz_temp = index( p_access->psz_location, '/' );
+                if ( psz_temp )
+                    i_current_length = psz_temp - p_access->psz_location + 1;
+            }
+            psz_temp = malloc( i_scheme_length + 3 + i_current_length +
+                               i_append_length + 1 );
+            if ( !psz_temp )
+                goto error;
+            char *psz = psz_temp;
+            memcpy( psz, p_access->psz_access, i_scheme_length );
+            psz += i_scheme_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_append_length );
+            psz += i_append_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