[Bug 506568] Re: poldek prepends extra slash to urls when http_proxy is used

Elan Ruusamäe glen at delfi.ee
Tue Jan 12 20:00:27 CET 2010


in  case if there's any interest, then my apache config and 404 handler
are:

apache.conf:

<Directory /mirror/ftp/pld/dists/th>
    # PLD Th -> PLD Th Archives
    ErrorDocument 404 /html/th-archive.php
</Directory>

th-archive.php:
<?php
# PLD Linux: old packages redirect to archive 404 Handler.
# Author: Elan Ruusamäe <glen at pld-linux.org>

// avoid magic slashes "escaping" redirect url
$request_uri = get_magic_quotes_gpc() ? stripslashes($_SERVER['REQUEST_URI']) : $_SERVER['REQUEST_URI'];

// remove full host portion if host is called as proxy.
$request_uri = preg_replace('#^http://'. quotemeta($_SERVER['SERVER_NAME']). '\b#', '', $request_uri);

function redirect($uri, $extra_msg = null) {
        global $request_uri;

        if (!preg_match('#^http://#', $uri)) {
                $uri = "http://{$_SERVER['SERVER_NAME']}$uri";
        }

        Header('HTTP/1.0 301 Content Moved');
        Header("Content-Location: $uri");
        Header("Location: $uri");
        error_log("archive redirect: $uri");
        die("Content moved to $uri.");
}

$errormap = array(
        '#^/pld/dists/th/PLD/([^/]+)/RPMS/(.+\.rpm)$#' => 'http://ftp.pld-linux.org/dists/th/.archive/PLD/$1/RPMS/$2',
);

// build destination url from $errormap
$uri = preg_replace(array_keys($errormap), array_values($errormap), $request_uri, 1);

if ($uri != $request_uri) {
    redirect($uri);
}

-- 
poldek prepends extra slash to urls when http_proxy is used
https://bugs.launchpad.net/bugs/506568
You received this bug notification because you are subscribed to PLD
Linux.

Status in poldek: New
Status in PLD Linux Distribution: New

Bug description:
poldek prepends extra slash to urls when http_proxy is used.

it fetches:
GET http://ftp1.pld-linux.org//dists/th/....rpm
must fetch:
GET http://ftp1.pld-linux.org/dists/th/....rpm

this breaks some setups of ftp mirrors.

to reproduce, find some http proxy, then use this code to test:

# rm -rf /tmp/test
# rpm -r /tmp/test --initdb
# poldek -r /tmp/test --fetch=/tmp/test -O 'proxy = http,ftp: http://proxy:3128/' -s http://ftp1.pld-linux.org/dists/th/PLD/x86_64/RPMS/ -u FHS -vv

Setting cache directory path to /var/cache/poldek
Enabling multilib mode, transaction color = 3
Loading [pndir]http://ftp1.pld-linux.org/dists/th/PLD/x86_64/RPMS/packages.ndir.gz...
  Loading directory index of http://ftp1.pld-linux.org/dists/th/PLD/x86_64/RPMS/packages.ndir.gz...
10921 packages read
Indexing...
Processing dependencies...
There are 1 package to install:
I FHS-2.3-29.x86_64
Retrieving http://ftp1.pld-linux.org//[...]/FHS-2.3-29.x86_64.rpm...
Connecting to proxy:3128...
< GET http://ftp1.pld-linux.org//dists/th/PLD/x86_64/RPMS/FHS-2.3-29.x86_64.rpm HTTP/1.1
<   Host: proxy
<   User-Agent: poldek-vhttp/0.30
> HTTP/1.0 200 OK
>   Date: Tue, 12 Jan 2010 18:49:33 GMT
>   Server: Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8l
>   Last-Modified: Wed, 21 Oct 2009 18:37:30 GMT
>   ETag: "dfe9e5c2-9044-4767645794207"
>   Accept-Ranges: bytes
>   Content-Length: 36932
>   Content-Type: application/x-rpm
>   Age: 223
>   Connection: close
Total file size 36932, 36932 to download, mtime Wed Oct 21 18:37:30 2009

.............................. 100.0% [36.1K (36.1K/s)]
Closing /tmp/test/FHS-2.3-29.x86_64.rpm (mtime 2009-10-21 15:37:30)




More information about the pld-bugs mailing list