<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Net::HTTP;

use strict;
use vars qw($VERSION @ISA $SOCKET_CLASS);

$VERSION = "6.06";
unless ($SOCKET_CLASS) {
    eval { require IO::Socket::INET } || require IO::Socket;
    $SOCKET_CLASS = "IO::Socket::INET";
}
require Net::HTTP::Methods;
require Carp;

@ISA = ($SOCKET_CLASS, 'Net::HTTP::Methods');

sub new {
    my $class = shift;
    Carp::croak("No Host option provided") unless @_;
    $class-&gt;SUPER::new(@_);
}

sub configure {
    my($self, $cnf) = @_;
    $self-&gt;http_configure($cnf);
}

sub http_connect {
    my($self, $cnf) = @_;
    $self-&gt;SUPER::configure($cnf);
}

1;

__END__

=head1 NAME

Net::HTTP - Low-level HTTP connection (client)

=head1 SYNOPSIS

 use Net::HTTP;
 my $s = Net::HTTP-&gt;new(Host =&gt; "www.perl.com") || die $@;
 $s-&gt;write_request(GET =&gt; "/", 'User-Agent' =&gt; "Mozilla/5.0");
 my($code, $mess, %h) = $s-&gt;read_response_headers;

 while (1) {
    my $buf;
    my $n = $s-&gt;read_entity_body($buf, 1024);
    die "read failed: $!" unless defined $n;
    last unless $n;
    print $buf;
 }

=head1 DESCRIPTION

The C&lt;Net::HTTP&gt; class is a low-level HTTP client.  An instance of the
C&lt;Net::HTTP&gt; class represents a connection to an HTTP server.  The
HTTP protocol is described in RFC 2616.  The C&lt;Net::HTTP&gt; class
supports C&lt;HTTP/1.0&gt; and C&lt;HTTP/1.1&gt;.

C&lt;Net::HTTP&gt; is a sub-class of C&lt;IO::Socket::INET&gt;.  You can mix the
methods described below with reading and writing from the socket
directly.  This is not necessary a good idea, unless you know what you
are doing.

The following methods are provided (in addition to those of
C&lt;IO::Socket::INET&gt;):

=over

=item $s = Net::HTTP-&gt;new( %options )

The C&lt;Net::HTTP&gt; constructor method takes the same options as
C&lt;IO::Socket::INET&gt;'s as well as these:

  Host:            Initial host attribute value
  KeepAlive:       Initial keep_alive attribute value
  SendTE:          Initial send_te attribute_value
  HTTPVersion:     Initial http_version attribute value
  PeerHTTPVersion: Initial peer_http_version attribute value
  MaxLineLength:   Initial max_line_length attribute value
  MaxHeaderLines:  Initial max_header_lines attribute value

The C&lt;Host&gt; option is also the default for C&lt;IO::Socket::INET&gt;'s
C&lt;PeerAddr&gt;.  The C&lt;PeerPort&gt; defaults to 80 if not provided.

The C&lt;Listen&gt; option provided by C&lt;IO::Socket::INET&gt;'s constructor
method is not allowed.

If unable to connect to the given HTTP server then the constructor
returns C&lt;undef&gt; and $@ contains the reason.  After a successful
connect, a C&lt;Net:HTTP&gt; object is returned.

=item $s-&gt;host

Get/set the default value of the C&lt;Host&gt; header to send.  The $host
must not be set to an empty string (or C&lt;undef&gt;) for HTTP/1.1.

=item $s-&gt;keep_alive

Get/set the I&lt;keep-alive&gt; value.  If this value is TRUE then the
request will be sent with headers indicating that the server should try
to keep the connection open so that multiple requests can be sent.

The actual headers set will depend on the value of the C&lt;http_version&gt;
and C&lt;peer_http_version&gt; attributes.

=item $s-&gt;send_te

Get/set the a value indicating if the request will be sent with a "TE"
header to indicate the transfer encodings that the server can choose to
use.  The list of encodings announced as accepted by this client depends
on availability of the following modules: C&lt;Compress::Raw::Zlib&gt; for
I&lt;deflate&gt;, and C&lt;IO::Compress::Gunzip&gt; for I&lt;gzip&gt;.

=item $s-&gt;http_version

Get/set the HTTP version number that this client should announce.
This value can only be set to "1.0" or "1.1".  The default is "1.1".

=item $s-&gt;peer_http_version

Get/set the protocol version number of our peer.  This value will
initially be "1.0", but will be updated by a successful
read_response_headers() method call.

=item $s-&gt;max_line_length

Get/set a limit on the length of response line and response header
lines.  The default is 8192.  A value of 0 means no limit.

=item $s-&gt;max_header_length

Get/set a limit on the number of header lines that a response can
have.  The default is 128.  A value of 0 means no limit.

=item $s-&gt;format_request($method, $uri, %headers, [$content])

Format a request message and return it as a string.  If the headers do
not include a C&lt;Host&gt; header, then a header is inserted with the value
of the C&lt;host&gt; attribute.  Headers like C&lt;Connection&gt; and
C&lt;Keep-Alive&gt; might also be added depending on the status of the
C&lt;keep_alive&gt; attribute.

If $content is given (and it is non-empty), then a C&lt;Content-Length&gt;
header is automatically added unless it was already present.

=item $s-&gt;write_request($method, $uri, %headers, [$content])

Format and send a request message.  Arguments are the same as for
format_request().  Returns true if successful.

=item $s-&gt;format_chunk( $data )

Returns the string to be written for the given chunk of data.  

=item $s-&gt;write_chunk($data)

Will write a new chunk of request entity body data.  This method
should only be used if the C&lt;Transfer-Encoding&gt; header with a value of
C&lt;chunked&gt; was sent in the request.  Note, writing zero-length data is
a no-op.  Use the write_chunk_eof() method to signal end of entity
body data.

Returns true if successful.

=item $s-&gt;format_chunk_eof( %trailers )

Returns the string to be written for signaling EOF when a
C&lt;Transfer-Encoding&gt; of C&lt;chunked&gt; is used.

=item $s-&gt;write_chunk_eof( %trailers )

Will write eof marker for chunked data and optional trailers.  Note
that trailers should not really be used unless is was signaled
with a C&lt;Trailer&gt; header.

Returns true if successful.

=item ($code, $mess, %headers) = $s-&gt;read_response_headers( %opts )

Read response headers from server and return it.  The $code is the 3
digit HTTP status code (see L&lt;HTTP::Status&gt;) and $mess is the textual
message that came with it.  Headers are then returned as key/value
pairs.  Since key letter casing is not normalized and the same key can
even occur multiple times, assigning these values directly to a hash
is not wise.  Only the $code is returned if this method is called in
scalar context.

As a side effect this method updates the 'peer_http_version'
attribute.

Options might be passed in as key/value pairs.  There are currently
only two options supported; C&lt;laxed&gt; and C&lt;junk_out&gt;.

The C&lt;laxed&gt; option will make read_response_headers() more forgiving
towards servers that have not learned how to speak HTTP properly.  The
C&lt;laxed&gt; option is a boolean flag, and is enabled by passing in a TRUE
value.  The C&lt;junk_out&gt; option can be used to capture bad header lines
when C&lt;laxed&gt; is enabled.  The value should be an array reference.
Bad header lines will be pushed onto the array.

The C&lt;laxed&gt; option must be specified in order to communicate with
pre-HTTP/1.0 servers that don't describe the response outcome or the
data they send back with a header block.  For these servers
peer_http_version is set to "0.9" and this method returns (200,
"Assumed OK").

The method will raise an exception (die) if the server does not speak
proper HTTP or if the C&lt;max_line_length&gt; or C&lt;max_header_length&gt;
limits are reached.  If the C&lt;laxed&gt; option is turned on and
C&lt;max_line_length&gt; and C&lt;max_header_length&gt; checks are turned off,
then no exception will be raised and this method will always
return a response code.

=item $n = $s-&gt;read_entity_body($buf, $size);

Reads chunks of the entity body content.  Basically the same interface
as for read() and sysread(), but the buffer offset argument is not
supported yet.  This method should only be called after a successful
read_response_headers() call.

The return value will be C&lt;undef&gt; on read errors, 0 on EOF, -1 if no data
could be returned this time, otherwise the number of bytes assigned
to $buf.  The $buf is set to "" when the return value is -1.

You normally want to retry this call if this function returns either
-1 or C&lt;undef&gt; with C&lt;$!&gt; as EINTR or EAGAIN (see L&lt;Errno&gt;).  EINTR
can happen if the application catches signals and EAGAIN can happen if
you made the socket non-blocking.

This method will raise exceptions (die) if the server does not speak
proper HTTP.  This can only happen when reading chunked data.

=item %headers = $s-&gt;get_trailers

After read_entity_body() has returned 0 to indicate end of the entity
body, you might call this method to pick up any trailers.

=item $s-&gt;_rbuf

Get/set the read buffer content.  The read_response_headers() and
read_entity_body() methods use an internal buffer which they will look
for data before they actually sysread more from the socket itself.  If
they read too much, the remaining data will be left in this buffer.

=item $s-&gt;_rbuf_length

Returns the number of bytes in the read buffer.  This should always be
the same as:

    length($s-&gt;_rbuf)

but might be more efficient.

=back

=head1 SUBCLASSING

The read_response_headers() and read_entity_body() will invoke the
sysread() method when they need more data.  Subclasses might want to
override this method to control how reading takes place.

The object itself is a glob.  Subclasses should avoid using hash key
names prefixed with C&lt;http_&gt; and C&lt;io_&gt;.

=head1 SEE ALSO

L&lt;LWP&gt;, L&lt;IO::Socket::INET&gt;, L&lt;Net::HTTP::NB&gt;

=head1 COPYRIGHT

Copyright 2001-2003 Gisle Aas.

This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

=cut
</pre></body></html>