]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Net.pl
* Merge changes from prposed changes
[infobot.git] / src / Net.pl
index 306e20a5542aac82da107557cf537bf1575b1f33..e1f091087ee8292c8f8d56b24188daad7e737a02 100644 (file)
@@ -77,17 +77,17 @@ sub ftpGet {
     if (defined $lsize) {
        &DEBUG("FTP: locsize => '$lsize'.");
        if ($size != $lsize) {
-           &WARN("FTP: downloaded file seems truncated. FIXME.");
+           &FIXME("FTP: downloaded file seems truncated.");
        }
     }
 
     my $delta_time     = &timedelta($start_time);
     if ($delta_time > 0 and $verbose_ftp) {
        &status(sprintf("FTP: %.02f sec to complete.", $delta_time));
-       my ($rateunit,$rate) = ("B", $size / $delta_time);
+       my ($rateunit,$rate) = ('B', $size / $delta_time);
        if ($rate > 1024) {
            $rate /= 1024;
-           $rateunit = "kB";
+           $rateunit = 'kB';
        }
        &status(sprintf("FTP: %.01f ${rateunit}/sec.", $rate));
     }
@@ -145,7 +145,7 @@ sub ftpList {
 
 ### LWP.
 # Usage: &getURL($url, [$post]);
-# todo: rename this to getHTTP
+# TODO: rename this to getHTTP
 sub getURL {
     my ($url,$post) = @_;
     my ($ua,$res,$req);
@@ -153,7 +153,7 @@ sub getURL {
     return unless &loadPerlModule("LWP::UserAgent");
 
     $ua = new LWP::UserAgent;
-    $ua->proxy('http', $param{'httpProxy'}) if &IsParam("httpProxy");
+    $ua->proxy('http', $param{'httpProxy'}) if &IsParam('httpProxy');
 
     if (defined $post) {
        $req = new HTTP::Request('POST',$url);
@@ -181,14 +181,19 @@ sub getURL {
 sub getURLAsFile {
     my ($url,$file) = @_;
     my ($ua,$res,$req);
+    my $time = time();
 
-    return unless &loadPerlModule("LWP::Simple");
+    unless (&loadPerlModule('LWP::UserAgent')) {
+       &::DEBUG('getURLAsFile: LWP::UserAgent not installed');
+       return;
+    }
 
-### PROXY NOT SUPPORTED WITH SIMPLE?
-###    $ua->proxy('http', $param{'httpProxy'}) if &IsParam("httpProxy");
-    my $time   = time();
+    $ua = new LWP::UserAgent;
+    $ua->proxy('http', $param{'httpProxy'}) if &IsParam('httpProxy');
+    $req = HTTP::Request->new('GET', $url);
     &status("getURLAsFile: getting '$url' as '$file'");
-    my $retval = getstore($url, $file);
+    $res = $ua->request($req, $file);
+
     my $delta_time     = time() - $time;
     if ($delta_time) {
        my $size = -s $file || 0;
@@ -196,7 +201,9 @@ sub getURLAsFile {
        &status("getURLAsFile: Done. ($rate kB/sec)");
     }
 
-    return $retval;
+    return $res;
 }
 
 1;
+
+# vim:ts=4:sw=4:expandtab:tw=80