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

Rémi Denis-Courmont remi at remlab.net
Mon Dec 2 12:42:04 CET 2013


On Mon, 2 Dec 2013 13:33:31 +0200 (EET), Martin Storsjö <martin at martin.st>
wrote:
> 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)

...and protocol-relative URIs (//...), and document-relative URIs (#...).

- does VLC have an existing utility function.

No. That's a known issue.

-- 
Rémi Denis-Courmont
Sent from my collocated server



More information about the vlc-devel mailing list