689 |
}; |
}; |
690 |
bless($self, $class); |
bless($self, $class); |
691 |
|
|
692 |
|
if (@_) { |
693 |
|
$self->{debug} = 1; |
694 |
|
warn "## Node debug on\n"; |
695 |
|
} |
696 |
|
|
697 |
$self ? return $self : return undef; |
$self ? return $self : return undef; |
698 |
} |
} |
699 |
|
|
789 |
|
|
790 |
my $status = -1; |
my $status = -1; |
791 |
|
|
792 |
warn $url; |
warn "## $url\n"; |
793 |
|
|
794 |
$url = new URI($url); |
$url = new URI($url); |
795 |
if ( |
if ( |
842 |
return -1; |
return -1; |
843 |
} |
} |
844 |
|
|
845 |
|
warn "## headers:\n$headers\n" if ($self->{debug}); |
846 |
|
|
847 |
print $sock $headers or |
print $sock $headers or |
848 |
carp "can't send headers to network:\n$headers\n" and return -1; |
carp "can't send headers to network:\n$headers\n" and return -1; |
849 |
|
|
850 |
if ($reqbody) { |
if ($reqbody) { |
851 |
|
warn "## request body:\n$headers\n" if ($self->{debug}); |
852 |
print $sock $$reqbody or |
print $sock $$reqbody or |
853 |
carp "can't send request body to network:\n$$reqbody\n" and return -1; |
carp "can't send request body to network:\n$$reqbody\n" and return -1; |
854 |
} |
} |
858 |
my ($schema, $res_status, undef) = split(/ */, $line, 3); |
my ($schema, $res_status, undef) = split(/ */, $line, 3); |
859 |
return if ($schema !~ /^HTTP/ || ! $res_status); |
return if ($schema !~ /^HTTP/ || ! $res_status); |
860 |
|
|
861 |
$self->{status} = $res_status; |
$status = $res_status; |
862 |
|
warn "## response status: $res_status\n" if ($self->{debug}); |
863 |
|
|
864 |
# skip rest of headers |
# skip rest of headers |
865 |
do { |
$line = <$sock>; |
866 |
|
while ($line) { |
867 |
$line = <$sock>; |
$line = <$sock>; |
868 |
chomp($line); |
$line =~ s/[\r\n]+$//; |
869 |
} until ($line eq ''); |
warn "## ", $line || 'NULL', " ##\n"; |
870 |
|
}; |
871 |
|
|
872 |
# read body |
# read body |
873 |
my $len = 0; |
$len = 0; |
874 |
do { |
do { |
875 |
$len = read($sock, my $buf, 8192); |
$len = read($sock, my $buf, 8192); |
876 |
$$resbody .= $buf if ($resbody); |
$$resbody .= $buf if ($resbody); |
877 |
} while ($len); |
} while ($len); |
878 |
|
|
879 |
|
|
880 |
|
warn "## response body:\n$$resbody\n" if ($self->{debug}); |
881 |
|
|
882 |
return $status; |
return $status; |
883 |
} |
} |
884 |
|
|