The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

UniEvent::HTTP::Response - HTTP client response class

SYNOPSIS

    http_request({
        uri => "http://example.com",
        response_callback => sub {
            my ($request, $response, $error) = @_;
            say $response->code;
            say $response->message;
            say $response->body;
            say Dumper($response->headers);
            say Dumper($response->cookies);
            ...
        },
    });
    
    my $response = http_request_sync($request);
    say $response->body;
    ...

DESCRIPTION

Objects of UniEvent::HTTP::Response represent http response on client side and are passed to request callbacks. Normally, response objects are not created by user, instead a response object is created automatically when parsing response. You can customize how response object is created via response_factory(), see UniEvent::HTTP::Request.

UniEvent::HTTP::Response inherits from Protocol::HTTP::Response. So for complete documenation you need to also read Protocol::HTTP::Response's docs.

See detailed description in corresponding method docs.

METHODS

All methods of Protocol::HTTP::Response also apply.

new()

Constructs a response object.

NOTE: If you create your own response class inherited from UniEvent::HTTP::Response, you must proxy to original new() method and use its result as the object you return. By default it is a reference to undef, you can upgrade it to hash-based object via XS::Framework::obj2hv:

    package MyResponse;
    use parent 'UniEvent::HTTP::Response';
    
    sub new {
        my $self = shift->SUPER::new();
        XS::Framework::obj2hv($self);
        $self->{prop} = "val";
        return $self;
    }
    
    ...
    $request->response_factory(sub { MyResponse->new });

is_done()

Returns true if response has been fully received including the whole body. This method can return false in partial_callback (see UniEvent::HTTP::Request) or if an error occurs.