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

Martin Storsjö martin at martin.st
Mon Dec 2 12:33:31 CET 2013


On Mon, 2 Dec 2013, Francois Cartegnie wrote:

> 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.

In RFC 2616, the redirects were said to be absolute, but in upcoming 
drafts it's allowed to be relative: 
http://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-25#section-7.1.2

> 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 );
> +        }

While this probably works for most common cases, it doesn't handle 
redirects relative to the root of the current server (and doesn't handle 
relative paths with .. either) - does VLC have an existing utility 
function for making an absolute path out of a base and a relative path? 
Even if one is ok with skipping those corner cases, this would probably be 
at least more readable if it would be factorized out somewhere.

// Martin



More information about the vlc-devel mailing list