summaryrefslogtreecommitdiffstats
path: root/perl-install/http.pm
blob: 8c19c104a5d7bf90ea9b4e13c9d596b78eb002ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package http; # $Id$

use IO::Socket;
use network::network;

my $sock;

sub getFile {
    local ($^W) = 0;

    my ($url) = @_;
    $sock->close if $sock;
    $url =~ m|/XXX$| and return; #- force closing connection.

    # can be used for ftp urls (with http proxy)
    my ($host, $port, $path) = $url =~ m,^(?:http|ftp)://([^/:]+)(?::(\d+))?(/\S*)?$,;
    defined $host or return undef;

    my $use_http_proxy = $ENV{PROXY} && $ENV{PROXYPORT};

    $sock = IO::Socket::INET->new(PeerAddr => $use_http_proxy ? $ENV{PROXY} : $host,
				  PeerPort => $use_http_proxy ? $ENV{PROXYPORT} : $port || 80,
				  Proto    => 'tcp',
				  Timeout  => 60) or die "can't connect $@";
    $sock->autoflush;
    print $sock join("\015\012" =>
		     "GET " . ($use_http_proxy ? $url : $path) . " HTTP/1.0",
		     "Host: $host" . ($port && ":$port"),
		     "User-Agent: DrakX/vivelinuxabaszindozs",
		     "", "");

    #- skip until empty line
    my $now = 0;
    my ($last, $buf, $tmp);
    my $read = sub { sysread($sock, $buf, 1) or die ''; $tmp .= $buf };
    do {
	$last = $now;
	&$read; &$read if $buf =~ /\015/;
	$now = $buf =~ /\012/;
    } until $now && $last;

    if ($tmp =~ /^(.*\b(\d+)\b.*)/ && $2 == 200) {
        $sock;
    } else {
	log::l("HTTP error: $1");
        undef;
    }
}

1;
:41:45 +0000'>2007-05-161-0/+2 * bump version (10.4.130) for toolsThierry Vignaud2007-05-161-1/+1 * Japanese translation reviewedYukiko Bando2007-05-151-8/+8 * small fix on previous commitPascal Rigaux2007-05-151-1/+2 * - bootloader-config:Pascal Rigaux2007-05-152-2/+27 * use "mkfs.ext3" instead of "mkfs.ext2 -J"Pascal Rigaux2007-05-144-2/+9 * re-sync after the big svn lossPascal Rigaux2007-05-142-0/+0 * re-sync after the big svn lossPascal Rigaux2007-05-14142-0/+0 * - do not ask for updates at end of installation when updates are alreadyPascal Rigaux2007-05-092-0/+8 * - localedrake:Pascal Rigaux2007-05-092-1/+3 * upJosé Melo2007-05-071-56/+9 * upJosé Melo2007-05-071-92/+60 * upJosé Melo2007-05-071-41/+15 * create udev nodes configuration file in /etc/udev/devices.d/ instead of conf....Olivier Blin2007-04-302-3/+4 * do not try to configure dvd devices during install since /dev is wiped out at...Olivier Blin2007-04-304-17/+2 * use ->last_usable_sector instead of {totalsectors} so that resizing aPascal Rigaux2007-04-301-1/+1 * "Free space" is better than "Empty space"Pascal Rigaux2007-04-291-1/+1 * - allow umounting cdrom during a transactionPascal Rigaux2007-04-272-0/+2 * re-sync after the big svn lossPascal Rigaux2007-04-251-715/+100 * re-sync after the big svn lossPascal Rigaux2007-04-25