/[Search-Estraier]/trunk/Estraier.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/Estraier.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 58 by dpavlin, Fri Jan 6 21:05:05 2006 UTC revision 59 by dpavlin, Fri Jan 6 23:29:58 2006 UTC
# Line 4  use 5.008; Line 4  use 5.008;
4  use strict;  use strict;
5  use warnings;  use warnings;
6    
7  our $VERSION = '0.00';  our $VERSION = '0.01';
8    
9  =head1 NAME  =head1 NAME
10    
# Line 1327  body will be saved within object. Line 1327  body will be saved within object.
1327    
1328  =cut  =cut
1329    
1330    use LWP::UserAgent;
1331    
1332  sub shuttle_url {  sub shuttle_url {
1333          my $self = shift;          my $self = shift;
1334    
# Line 1345  sub shuttle_url { Line 1347  sub shuttle_url {
1347                  return -1;                  return -1;
1348          }          }
1349    
1350          my ($host,$port,$query) = ($url->host, $url->port, $url->path);          my $ua = LWP::UserAgent->new;
1351            $ua->agent( "Search-Estraier/$Search::Estraier::VERSION" );
         if ($self->{pxhost}) {  
                 ($host,$port) = ($self->{pxhost}, $self->{pxport});  
                 $query = "http://$host:$port/$query";  
         }  
   
         $query .= '?' . $url->query if ($url->query && ! $reqbody);  
   
         my $headers;  
1352    
1353            my $req;
1354          if ($reqbody) {          if ($reqbody) {
1355                  $headers .= "POST $query HTTP/1.0\r\n";                  $req = HTTP::Request->new(POST => $url);
1356          } else {          } else {
1357                  $headers .= "GET $query HTTP/1.0\r\n";                  $req = HTTP::Request->new(GET => $url);
         }  
   
         $headers .= "Host: " . $url->host . ":" . $url->port . "\r\n";  
         $headers .= "Connection: close\r\n";  
         $headers .= "User-Agent: Search-Estraier/$Search::Estraier::VERSION\r\n";  
         $headers .= "Content-Type: $content_type\r\n";  
         $headers .= "Authorization: Basic $self->{auth}\r\n";  
         my $len = 0;  
         {  
                 use bytes;  
                 $len = length($reqbody) if ($reqbody);  
         }  
         $headers .= "Content-Length: $len\r\n";  
         $headers .= "\r\n";  
   
         my $sock = IO::Socket::INET->new(  
                 PeerAddr        => $host,  
                 PeerPort        => $port,  
                 Proto           => 'tcp',  
                 Timeout         => $self->{timeout} || 90,  
         );  
   
         if (! $sock) {  
                 carp "can't open socket to $host:$port";  
                 return -1;  
1358          }          }
1359    
1360          warn $headers if ($self->{debug});          $req->headers->header( 'Host' => $url->host . ":" . $url->port );
1361            $req->headers->header( 'Connection', 'close' );
1362            $req->headers->header( 'Authorization', 'Basic ' . $self->{auth} );
1363            $req->content_type( $content_type );
1364    
1365          print $sock $headers or          warn $req->headers->as_string,"\n" if ($self->{debug});
                 carp "can't send headers to network:\n$headers\n" and return -1;  
1366    
1367          if ($reqbody) {          if ($reqbody) {
1368                  warn "$reqbody\n" if ($self->{debug});                  warn "$reqbody\n" if ($self->{debug});
1369                  print $sock $reqbody or                  $req->content( $reqbody );
                         carp "can't send request body to network:\n$$reqbody\n" and return -1;  
1370          }          }
1371    
1372          my $line = <$sock>;          my $res = $ua->request($req) || croak "can't make request to $url: $!";
1373          chomp($line);  
1374          my ($schema, $res_status, undef) = split(/  */, $line, 3);          warn "## response status: ",$res->status_line,"\n" if ($self->{debug});
1375          return if ($schema !~ /^HTTP/ || ! $res_status);  
1376            return -1 if (! $res->is_success);
1377          $self->{status} = $res_status;  
1378          warn "## response status: $res_status\n" if ($self->{debug});          ($self->{status}, $self->{status_message}) = split(/\s+/, $res->status_line, 2);
   
         # skip rest of headers  
         $line = <$sock>;  
         while ($line) {  
                 $line = <$sock>;  
                 $line =~ s/[\r\n]+$//;  
                 warn "## ", $line || 'NULL', " ##\n" if ($self->{debug});  
         };  
1379    
1380          # read body          $$resbody .= $res->content;
         $len = 0;  
         do {  
                 $len = read($sock, my $buf, 8192);  
                 $$resbody .= $buf if ($resbody);  
         } while ($len);  
1381    
1382          warn "## response body:\n$$resbody\n" if ($resbody && $self->{debug});          warn "## response body:\n$$resbody\n" if ($resbody && $self->{debug});
1383    

Legend:
Removed from v.58  
changed lines
  Added in v.59

  ViewVC Help
Powered by ViewVC 1.1.26