home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-2 / Inter.Net 55-2.iso / Mandrake / mdkinst / usr / bin / perl-install / http.pm < prev    next >
Encoding:
Perl POD Document  |  2000-01-12  |  874 b   |  44 lines

  1. package http;
  2.  
  3. use IO::Socket;
  4.  
  5. use install_any;
  6. use network;
  7.  
  8.  
  9. my $sock;
  10.  
  11. sub getFile($) {
  12.     local($^W) = 0;
  13.  
  14.     my ($host, $port, $path) = $ENV{URLPREFIX} =~ m,^http://([^/:]+)(?::(\d+))?(/\S*)?$,;
  15.     $host = network::resolv($host);
  16.     $path .= "/" . install_any::relGetFile($_[0]);
  17.  
  18.     $sock->close if $sock;
  19.     $sock = IO::Socket::INET->new(PeerAddr => $host,
  20.                   PeerPort => $port || 80,
  21.                   Proto    => 'tcp',
  22.                   Timeout  => 60) or die "can't connect ";
  23.     $sock->autoflush;
  24.     print $sock join("\015\012" =>
  25.              "GET $path HTTP/1.0",
  26.              "Host: $host" . ($port && ":$port"),
  27.              "User-Agent: DrakX/vivelinuxabaszindozs",
  28.              "", "");
  29.  
  30.     
  31.     local $_;
  32.     my ($now, $last) = 0;
  33.     do {
  34.     $last = $now;
  35.     sysread($sock, $_, 1) || die;
  36.     sysread($sock, $_, 1) || die if /\015/;
  37.     $now = /\012/;
  38.     } until ($now && $last);
  39.  
  40.     $sock;
  41. }
  42.  
  43. 1;
  44.