NAME
AnyEvent::HTTP::Response - HTTP Response object for AnyEvent::HTTP
VERSION
version 0.302
SYNOPSIS
# parses argument list passed to AnyEvent::HTTP::http_request callback
AnyEvent::HTTP::http_request(
GET => $uri,
sub {
my $res = AnyEvent::HTTP::Response->new(@_);
# inspect attributes
print $res->header('Content-Type');
print $res->body;
# upgrade to HTTP::Response
my $http_res = $res->to_http_message;
if( !$http_res->is_success ){
print $http_res->status_line;
}
}
);
DESCRIPTION
This object represents an HTTP response from AnyEvent::HTTP.
This is a companion class to AnyEvent::HTTP::Request.
It parses the arguments passed to the final callback in "http_request" in AnyEvent::HTTP (or produces the arguments that should be passed to that, depending on how you'd like to use it). and wraps them in an object.
It can also be converted from or to the more featureful HTTP::Response.
CLASS METHODS
new
Accepts an argument list like the callback provided to "http_request" in AnyEvent::HTTP (see "parse_args"):
AnyEvent::HTTP::Response->new($body, \%headers);
Alternatively accepts an instance of HTTP::Response (see "from_http_message"):
AnyEvent::HTTP::Response->new(
HTTP::Response->new( $code, $reason, $headers, $body )
);
Also accepts a single hashref of named attributes (see "ATTRIBUTES"):
AnyEvent::HTTP::Response->new({
body => $body,
headers => \%headers,
pseudo_headers => \%pseudo,
});
parse_args
Called by the constructor to parse the argument list passed to the callback in "http_request" in AnyEvent::HTTP and return a hashref which will be the basis for the object.
The list should look like ($body, \%headers)
.
This will separate the "pseudo" headers from the regular http headers as described by "http_request" in AnyEvent::HTTP (http headers are lower-cased and pseudo headers start with an upper case letter).
from_http_message
Called by the constructor when "new" is passed an instance of HTTP::Response.
ATTRIBUTES
body
Response content body
content
Alias for "body"
headers
HTTP Response headers
pseudo_headers
A hashref of extra fields that "http_request" in AnyEvent::HTTP returns with the http headers (the ones that start with an upper-case letter... Status, Reason, etc).
METHODS
args
Returns a list of arguments like those passed to the callback in "http_request" in AnyEvent::HTTP.
to_http_message
Returns an instance of HTTP::Response to provide additional functionality.
SEE ALSO
AnyEvent::HTTP::Message (base class)
HTTP::Response More featureful object
HTTP::Message::PSGI Create an HTTP::Response from a PSGI arrayref
AUTHOR
Randy Stauner <rwstauner@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Randy Stauner.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.