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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
use strict;
use warnings;
use Test::More;
use HTTP::Request ();
use LWP::UserAgent ();
use LWP::Protocol ();
plan tests => 2;
LWP::Protocol::implementor(http => 'myhttp');
my $ua = LWP::UserAgent->new(keep_alive => 1);
$ua->proxy('http' => "http://proxy.activestate.com");
my $req = HTTP::Request->new(GET => 'http://gisle:aas@www.activestate.com');
my $res = $ua->request($req);
isa_ok($res, 'HTTP::Response', 'activeState: got a response');
ok($res->as_string, 'activeState: has content');
exit;
{
package myhttp;
use parent 'LWP::Protocol::http';
sub _conn_class {
"myconn";
}
}
{
package myconn;
sub new {
my $class = shift;
return bless {}, $class;
}
sub format_request {
my $self = shift;
return "REQ";
}
sub syswrite {
my $self = shift;
return length($_[0]);
}
sub read_response_headers {
my $self = shift;
return (302, "OK", "Content-type", "text/plain");
}
sub read_entity_body {
my $self = shift;
return 0;
}
sub peer_http_version {
my $self = shift;
return "1.1";
}
sub increment_response_count {
my $self = shift;
++$self->{count};
}
sub get_trailers {
my $self = shift;
return ();
}
}
{
package myhttp::SocketMethods;
sub ping {
my $self = shift;
!$self->can_read(0);
}
sub increment_response_count {
my $self = shift;
return ++${*$self}{'myhttp_response_count'};
}
}
{
package myhttp::Socket;
use parent -norequire => qw(myhttp::SocketMethods);
use parent qw(Net::HTTP);
}
|