Patch available for relative redirections (SR_ERROR_INVALID_URL)

nephylim
2013-05-14
2013-05-14
  • nephylim
    nephylim
    2013-05-14

    When a server sends a redirection (Location header) with a relative URL instead of absolute, streamripper dies with SR_ERROR_INVALID_URL error message.
    The faulty one in this story, is the server by not applying RFC 2616, but it is better to have a client-side solution to this problem to allow the download as expected by the end-user.

    I created this patch for lib/http.c file :

    cat http.c.patch-20130514

    --- http.c      2013-05-14 11:21:15.164984928 +0200
    +++ http.c.patched-20130514     2013-05-14 11:17:30.490985091 +0200
    @@ -103,8 +103,19 @@
            if (*info->http_location) {
                /* RECURSIVE CASE */
                debug_printf ("Redirecting: %s\n", info->http_location);
    -           url = info->http_location;
    -           return http_sc_connect (rmi, sock, info->http_location,
    +           /* PATCH for non-absolute redirects, when servers are not compliant to RFC */
    +           /* see http://tools.ietf.org/html/rfc2616#section-14.30 */
    +           /* written by Eugene Adell eugene_adell@hotmail.com */
    +           if ( (strchr(info->http_location, '/') - info->http_location) == 0 ) {
    +               char localbuffer [1024];
    +               sprintf(localbuffer, "http://%s:%d%s", url_info.host, url_info.port,info->http_location);
    +               debug_printf ("Location gave a relative URL, we must rebuild it to absolute : URL will be %s \n", localbuffer);
    +               url = localbuffer;
    +           }
    +           else {
    +               url = info->http_location;
    +           }
    +           return http_sc_connect (rmi, sock, url,
                                        proxyurl, info, useragent, if_name);
            } else {
                break;
    

    Apply it like any other patch :
    patch < http.c.patch-20130514

     
    Last edit: nephylim 2013-05-14
    Attachments