NAME
Reflexive::Client::HTTP - A Reflex(ive) HTTP Client
VERSION
version 0.007
SYNOPSIS
my $ua = Reflexive::Client::HTTP->new;
for my $url (qw( http://duckduckgo.com/ http://perl.org/ )) {
$ua->request(
HTTP::Request->new( GET => $url ),
sub { print $url." gave me a ".$_->code."\n" },
);
}
Reflex->run_all();
DESCRIPTION
Reflexive::Client::HTTP is an HTTP user-agent for Reflex. At the current state it is only a wrapper around POE::Component::Client::HTTP, but we will try to assure stability to the API.
ATTRIBUTES
agent
The useragent to use for the HTTP client. Defaults to the package name and the current version of it.
from
from
holds an e-mail address where the client's administrator and/or maintainer may be reached. It defaults to undef, which means no From header will be included in requests.
protocol
protocol
advertises the protocol that the client wishes to see. Under normal circumstances, it should be left to its default value: "HTTP/1.1".
timeout
So far see "Timeout" in POE::Component::Client::HTTP.
max_size
max_size
specifies the largest response to accept from a server. The content of larger responses will be truncated to OCTET octets. This has been used to return the <head></head> section of web pages without the need to wade through <body></body>.
follow_redirects
follow_redirects
specifies how many redirects (e.g. 302 Moved) to follow. If not specified defaults to 0, and thus no redirection is followed. This maintains compatibility with the previous behavior, which was not to follow redirects at all.
If redirects are followed, a response chain should be built, and can be accessed through $event->response->previous() or $_->previous() if you use a callback on "request". See HTTP::Response for details here.
proxy
proxy
specifies one or more proxy hosts that requests will be passed through. If not specified, proxy servers will be taken from the HTTP_PROXY (or http_proxy) environment variable. No proxying will occur unless proxy
is set or one of the environment variables exists.
The proxy can be specified either as a host and port, or as one or more URLs. proxy
URLs must specify the proxy port, even if it is 80.
proxy => [ "127.0.0.1", 80 ],
proxy => "http://127.0.0.1:80/",
proxy
may specify multiple proxies separated by commas. Reflexive::Client::HTTP will choose proxies from this list at random. This is useful for load balancing requests through multiple gateways.
proxy => "http://127.0.0.1:80/,http://127.0.0.1:81/",
no_proxy
no_proxy
specifies a list of server hosts that will not be proxied. It is useful for local hosts and hosts that do not properly support proxying. If no_proxy
is not specified, a list will be taken from the NO_PROXY environment variable.
no_proxy => [ "localhost", "127.0.0.1" ],
no_proxy => "localhost,127.0.0.1",
bind_addr
Specify bind_addr
to bind all client sockets to a particular local address.
METHODS
request
This function takes as first argument a HTTP::Request and any additional number of arguments you want to give. If you are accessing the client via watches
then the args are in the "args" in Reflexive::Client::HTTP::ResponseEvent attribute.
If you give as first additional argumnet a CodeRef, then this one gets executed instead of the emitting of the Reflexive::Client::HTTP::ResponseEvent. It gets all other additional arguments of the request
call given as own arguments. Additionall we set $_ to the HTTP::Response object.
$ua->request( HTTP::Request->new( GET => "http://duckduckgo.com/" ), sub {
print "DuckDuckGo gave me ".$_->code."\n";
});
If you require access to the HTTP::Request object via this method, you need to apply it as one of your arguments yourself on the call of request
A special feature of this fuction is the option to directly chain it. If you are using the CodeRef callback, you can return a new HTTP::Request from this CodeRef together with a new CodeRef and more arguments, to trigger another request for another callback.
$ua->request( HTTP::Request->new( GET => "http://duckduckgo.com/" ), sub {
print "DuckDuckGo gave me ".$_->code."\n";
return HTTP::Request->new( GET => "http://perl.org/" ), sub {
print "Perl gave me ".$_->code."\n";
return HTTP::Request->new( GET => "http://metacpan.org/" ), sub {
print "MetaCPAN gave me ".$_->code."\n";
};
};
});
SEE ALSO
THANKS
Big thanks to dngor for helping me through the process to understand Reflex enough for making this. Most of this is based on his code.
SUPPORT
IRC
Join #reflex on irc.perl.org. Highlight Getty or dngor for fast reaction :).
Repository
http://github.com/Getty/p5-reflexive-client-http
Pull request and additional contributors are welcome
Issue Tracker
http://github.com/Getty/p5-reflexive-client-http/issues
AUTHOR
Torsten Raudssus <torsten@raudss.us>
COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Torsten Raudssus.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.