# $Id: http.pm,v 1.67 2004/03/10 20:10:18 gisle Exp $ # package LWP::Protocol::http; use strict; require LWP::Debug; require HTTP::Response; require HTTP::Status; require Net::HTTP; use vars qw(@ISA @EXTRA_SOCK_OPTS); require LWP::Protocol; @ISA = qw(LWP::Protocol); my $CRLF = "\015\012"; sub _new_socket { my($self, $host, $port, $timeout) = @_; my $conn_cache = $self->{ua}{conn_cache}; if ($conn_cache) { if (my $sock = $conn_cache->withdraw("http", "$host:$port")) { return $sock if $sock && !$sock->can_read(0); # if the socket is readable, then either the peer has closed the # connection or there are some garbage bytes on it. In either # case we abandon it. $sock->close; } } local($^W) = 0; # IO::Socket::INET can be noisy my $sock = $self->socket_class->new(PeerAddr => $host, PeerPort => $port, Proto => 'tcp', Timeout => $timeout, KeepAlive => !!$conn_cache, SendTE => 1, $self->_extra_sock_opts($host, $port), ); unless ($sock) { # IO::Socket::INET leaves additional error messages in $@ $@ =~ s/^.*?: //; die "Can't connect to $host:$port ($@)"; } # perl 5.005's IO::Socket does not have the blocking method. eval { $sock->blocking(0); }; $sock; } sub socket_class { my $self = shift; (ref($self) || $self) . "::Socket"; } sub _extra_sock_opts # to be overridden by subclass { return @EXTRA_SOCK_OPTS; } sub _check_sock { #my($self, $req, $sock) = @_; } sub _get_sock_info {