POE-Component-Client-HTTP
view release on metacpan or search on metacpan
Proxy => "http://127.0.0.1:80/,http://127.0.0.1:81/",
Streaming => OCTETS
"Streaming" changes allows Client::HTTP to return large content in
chunks (of OCTETS octets each) rather than combine the entire content
into a single HTTP::Response object.
By default, Client::HTTP reads the entire content for a response into
memory before returning an HTTP::Response object. This is obviously
bad for applications like streaming MP3 clients, because they often
fetch songs that never end. Yes, they go on and on, my friend.
When "Streaming" is set to nonzero, however, the response handler
receives chunks of up to OCTETS octets apiece. The response handler
accepts slightly different parameters in this case. ARG0 is also an
HTTP::Response object but it does not contain response content, and
ARG1 contains a a chunk of raw response content, or undef if the
stream has ended.
sub streaming_response_handler {
my $response_packet = $_[ARG1];
my ($response, $data) = @$response_packet;
print SAVED_STREAM $data if defined $data;
}
FollowRedirects => $number_of_hops_to_follow
"FollowRedirects" 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.
my $count = $kernel->call('ua' => 'pending_requests_count');
NOTE: Sometimes the count might not be what you expected, because
responses are currently in POE's queue and you haven't processed them.
This could happen if you configure the "ConnectionManager"'s concurrency
to a high enough value.
cancel
Cancel a specific HTTP request. Requires a reference to the original
request (blessed or stringified) so it knows which one to cancel. See
"progress handler" below for notes on canceling streaming requests.
To cancel a request based on its blessed HTTP::Request object:
$kernel->post( component => cancel => $http_request );
To cancel a request based on its stringified HTTP::Request object:
$kernel->post( component => cancel => "$http_request" );
shutdown
README.mkdn view on Meta::CPAN
Proxy => "http://127.0.0.1:80/,http://127.0.0.1:81/",
- Streaming => OCTETS
`Streaming` changes allows Client::HTTP to return large content in
chunks (of OCTETS octets each) rather than combine the entire content
into a single HTTP::Response object.
By default, Client::HTTP reads the entire content for a response into
memory before returning an HTTP::Response object. This is obviously
bad for applications like streaming MP3 clients, because they often
fetch songs that never end. Yes, they go on and on, my friend.
When `Streaming` is set to nonzero, however, the response handler
receives chunks of up to OCTETS octets apiece. The response handler
accepts slightly different parameters in this case. ARG0 is also an
HTTP::Response object but it does not contain response content,
and ARG1 contains a a chunk of raw response
content, or undef if the stream has ended.
sub streaming_response_handler {
my $response_packet = $_[ARG1];
my ($response, $data) = @$response_packet;
print SAVED_STREAM $data if defined $data;
}
- FollowRedirects => $number\_of\_hops\_to\_follow
`FollowRedirects` 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,
README.mkdn view on Meta::CPAN
my $count = $kernel->call('ua' => 'pending_requests_count');
NOTE: Sometimes the count might not be what you expected, because responses
are currently in POE's queue and you haven't processed them. This could happen
if you configure the `ConnectionManager`'s concurrency to a high enough value.
## cancel
Cancel a specific HTTP request. Requires a reference to the original
request (blessed or stringified) so it knows which one to cancel. See
["progress handler"](#progress-handler) below for notes on canceling streaming requests.
To cancel a request based on its blessed HTTP::Request object:
$kernel->post( component => cancel => $http_request );
To cancel a request based on its stringified HTTP::Request object:
$kernel->post( component => cancel => "$http_request" );
## shutdown
lib/POE/Component/Client/HTTP.pm view on Meta::CPAN
Proxy => "http://127.0.0.1:80/,http://127.0.0.1:81/",
=item Streaming => OCTETS
C<Streaming> changes allows Client::HTTP to return large content in
chunks (of OCTETS octets each) rather than combine the entire content
into a single HTTP::Response object.
By default, Client::HTTP reads the entire content for a response into
memory before returning an HTTP::Response object. This is obviously
bad for applications like streaming MP3 clients, because they often
fetch songs that never end. Yes, they go on and on, my friend.
When C<Streaming> is set to nonzero, however, the response handler
receives chunks of up to OCTETS octets apiece. The response handler
accepts slightly different parameters in this case. ARG0 is also an
HTTP::Response object but it does not contain response content,
and ARG1 contains a a chunk of raw response
content, or undef if the stream has ended.
sub streaming_response_handler {
my $response_packet = $_[ARG1];
my ($response, $data) = @$response_packet;
print SAVED_STREAM $data if defined $data;
}
=item FollowRedirects => $number_of_hops_to_follow
C<FollowRedirects> 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,
lib/POE/Component/Client/HTTP.pm view on Meta::CPAN
my $count = $kernel->call('ua' => 'pending_requests_count');
NOTE: Sometimes the count might not be what you expected, because responses
are currently in POE's queue and you haven't processed them. This could happen
if you configure the C<ConnectionManager>'s concurrency to a high enough value.
=head2 cancel
Cancel a specific HTTP request. Requires a reference to the original
request (blessed or stringified) so it knows which one to cancel. See
L<progress handler> below for notes on canceling streaming requests.
To cancel a request based on its blessed HTTP::Request object:
$kernel->post( component => cancel => $http_request );
To cancel a request based on its stringified HTTP::Request object:
$kernel->post( component => cancel => "$http_request" );
=head2 shutdown
lib/POE/Component/Client/HTTP/Request.pm view on Meta::CPAN
my ($self) = @_;
DEBUG and warn "in return_response ", sprintf ("0x%02X", $self->[REQ_STATE]);
return if ($self->[REQ_STATE] & RS_POSTED);
my $response = $self->[REQ_RESPONSE];
# If we have a cookie jar, have it frob our headers. LWP rocks!
$self->[REQ_FACTORY]->frob_cookies ($response);
# If we're done, send back the HTTP::Response object, which
# is filled with content if we aren't streaming, or empty
# if we are. that there's no ARG1 lets the client know we're done
# with the content in the latter case
if ($self->[REQ_STATE] & RS_DONE) {
DEBUG and warn "done; returning $response for ", $self->[REQ_ID];
$self->[REQ_POSTBACK]->($self->[REQ_RESPONSE]);
$self->[REQ_STATE] |= RS_POSTED;
#warn "state is now ", $self->[REQ_STATE];
}
elsif ($self->[REQ_STATE] & RS_IN_CONTENT) {
# If we are streaming, send the chunk back to the client session.
# Otherwise add the new octets to the response's content.
# This should only add up to content-length octets total!
if ($self->[REQ_FACTORY]->is_streaming) {
DEBUG and warn "returning partial $response";
$self->[REQ_POSTBACK]->($self->[REQ_RESPONSE], $self->[REQ_BUFFER]);
}
else {
DEBUG and warn "adding to $response";
$self->[REQ_RESPONSE]->add_content($self->[REQ_BUFFER]);
}
}
$self->[REQ_BUFFER] = '';
}
lib/POE/Component/Client/HTTP/RequestFactory.pm view on Meta::CPAN
push(
@$agent,
sprintf(
'POE-Component-Client-HTTP/%s (perl; N; POE; en; rv:%f)',
$v, $v
)
) unless @$agent;
my $max_size = delete $params->{MaxSize};
my $streaming = delete $params->{Streaming};
my $protocol = delete $params->{Protocol};
$protocol = 'HTTP/1.1' unless defined $protocol and length $protocol;
my $cookie_jar = delete $params->{CookieJar};
my $from = delete $params->{From};
my $no_proxy = delete $params->{NoProxy};
my $proxy = delete $params->{Proxy};
my $follow_redirects = delete $params->{FollowRedirects} || 0;
my $timeout = delete $params->{Timeout};
lib/POE/Component/Client/HTTP/RequestFactory.pm view on Meta::CPAN
if (defined $no_proxy) {
unless (ref($no_proxy) eq 'ARRAY') {
$no_proxy = [ split(/\s*\,\s*/, $no_proxy) ];
}
}
$timeout = 180 unless (defined $timeout and $timeout > 0);
my $self = [
$agent, # FCT_AGENT
$streaming, # FCT_STREAMING
$max_size, # FCT_MAXSIZE
$protocol, # FCT_PROTOCOL
$cookie_jar, # FCT_COOKIEJAR
$from, # FCT_FROM
$no_proxy, # FCT_NOPROXY
$proxy, # FCT_HTTP_PROXY
$follow_redirects, # FCT_FOLLOWREDIRECTS
$timeout, # FCT_TIMEOUT
];
lib/POE/Component/Client/HTTP/RequestFactory.pm view on Meta::CPAN
sub timeout {
my ($self, $timeout) = @_;
if (defined $timeout) {
$self->[FCT_TIMEOUT] = $timeout;
}
return $self->[FCT_TIMEOUT];
}
=head2 is_streaming
Accessor for the Streaming parameter
=cut
sub is_streaming {
my ($self) = @_;
DEBUG and warn(
"FCT: this is "
. ($self->[FCT_STREAMING] ? "" : "not ")
. "streaming"
);
return $self->[FCT_STREAMING];
}
=head2 agent
Accessor to the Agent parameter
=cut
lib/POE/Component/Client/HTTP/RequestFactory.pm view on Meta::CPAN
# Add a From: header if one isn't included.
if (defined $self->from) {
my $req_from = $http_request->from();
unless (defined $req_from and length $req_from) {
$http_request->from( $self->from );
}
}
# Add a Content-Length header if this request has content but
# doesn't have a Content-Length header already. Also, don't do it
# if the content is a reference, as this means we're streaming via
# callback.
if (
length($http_request->content()) and
!ref($http_request->content()) and
!$http_request->content_length()
) {
use bytes;
$http_request->content_length(length($http_request->content()));
}
( run in 0.269 second using v1.01-cache-2.11-cpan-4d50c553e7e )