AnyEvent-HTTP
view release on metacpan or search on metacpan
Note that this module will prefer an existing persistent connection,
even if that connection was made using another proxy. If you need to
ensure that a new connection is made in this case, you can either force
C<persistent> to false or e.g. use the proxy address in your C<sessionid>.
=item body => $string
The request body, usually empty. Will be sent as-is (future versions of
this module might offer more options).
=item cookie_jar => $hash_ref
Passing this parameter enables (simplified) cookie-processing, loosely
based on the original netscape specification.
The C<$hash_ref> must be an (initially empty) hash reference which
will get updated automatically. It is possible to save the cookie jar
to persistent storage with something like JSON or Storable - see the
C<AnyEvent::HTTP::cookie_jar_expire> function if you wish to remove
expired or session-only cookies, and also for documentation on the format
of the cookie jar.
Note that this cookie implementation is not meant to be complete. If
you want complete cookie management you have to do that on your
own. C<cookie_jar> is meant as a quick fix to get most cookie-using sites
working. Cookies are a privacy disaster, do not use them unless required
to.
When cookie processing is enabled, the C<Cookie:> and C<Set-Cookie:>
headers will be set and handled by this module, otherwise they will be
left untouched.
=item tls_ctx => $scheme | $tls_ctx
Specifies the AnyEvent::TLS context to be used for https connections. This
parameter follows the same rules as the C<tls_ctx> parameter to
L<AnyEvent::Handle>, but additionally, the two strings C<low> or
C<high> can be specified, which give you a predefined low-security (no
verification, highest compatibility) and high-security (CA and common-name
verification) TLS context.
The default for this option is C<low>, which could be interpreted as "give
me the page, no matter what".
See also the C<sessionid> parameter.
=item sessionid => $string
The module might reuse connections to the same host internally (regardless
of other settings, such as C<tcp_connect> or C<proxy>). Sometimes (e.g.
when using TLS or a specfic proxy), you do not want to reuse connections
from other sessions. This can be achieved by setting this parameter to
some unique ID (such as the address of an object storing your state data
or the TLS context, or the proxy IP) - only connections using the same
unique ID will be reused.
=item on_prepare => $callback->($fh)
In rare cases you need to "tune" the socket before it is used to
connect (for example, to bind it on a given IP address). This parameter
overrides the prepare callback passed to C<AnyEvent::Socket::tcp_connect>
and behaves exactly the same way (e.g. it has to provide a
timeout). See the description for the C<$prepare_cb> argument of
C<AnyEvent::Socket::tcp_connect> for details.
=item tcp_connect => $callback->($host, $service, $connect_cb, $prepare_cb)
In even rarer cases you want total control over how AnyEvent::HTTP
establishes connections. Normally it uses L<AnyEvent::Socket::tcp_connect>
to do this, but you can provide your own C<tcp_connect> function -
obviously, it has to follow the same calling conventions, except that it
may always return a connection guard object.
The connections made by this hook will be treated as equivalent to
connections made the built-in way, specifically, they will be put into
and taken from the persistent connection cache. If your C<$tcp_connect>
function is incompatible with this kind of re-use, consider switching off
C<persistent> connections and/or providing a C<sessionid> identifier.
There are probably lots of weird uses for this function, starting from
tracing the hosts C<http_request> actually tries to connect, to (inexact
but fast) host => IP address caching or even socks protocol support.
=item on_header => $callback->($headers)
When specified, this callback will be called with the header hash as soon
as headers have been successfully received from the remote server (not on
locally-generated errors).
It has to return either true (in which case AnyEvent::HTTP will continue),
or false, in which case AnyEvent::HTTP will cancel the download (and call
the finish callback with an error code of C<598>).
This callback is useful, among other things, to quickly reject unwanted
content, which, if it is supposed to be rare, can be faster than first
doing a C<HEAD> request.
The downside is that cancelling the request makes it impossible to re-use
the connection. Also, the C<on_header> callback will not receive any
trailer (headers sent after the response body).
Example: cancel the request unless the content-type is "text/html".
on_header => sub {
$_[0]{"content-type"} =~ /^text\/html\s*(?:;|$)/
},
=item on_body => $callback->($partial_body, $headers)
When specified, all body data will be passed to this callback instead of
to the completion callback. The completion callback will get the empty
string instead of the body data.
It has to return either true (in which case AnyEvent::HTTP will continue),
or false, in which case AnyEvent::HTTP will cancel the download (and call
the completion callback with an error code of C<598>).
The downside to cancelling the request is that it makes it impossible to
re-use the connection.
( run in 0.968 second using v1.01-cache-2.11-cpan-2398b32b56e )