NAME

Unblock::HTTP2::Client - one HTTP/2 client connection

SYNOPSIS

use Uniform::HTTP::Request;
use Unblock::HTTP2::Client;

my $client = Unblock::HTTP2::Client->new;

my $transaction = $client->request(
    Uniform::HTTP::Request->new(
        method    => 'GET',
        target    => '/',
        scheme    => 'https',
        authority => 'example.com',
    ),

    on_response => sub {
        my ($transaction, $response) = @_;
    },

    on_body => sub {
        my ($transaction, $response, $bytes) = @_;
    },

    on_complete => sub {
        my ($transaction) = @_;
    },
);

DESCRIPTION

A Client owns one HTTP/2 client session.

It does not create a socket, perform TLS, run an event loop, or own a transport write queue.

Feed received HTTP/2 bytes to input(). Drain generated bytes from output() while want_write() is true.

Many request transactions can be active at once.

CONSTRUCTOR

new() accepts an initial settings hash, max_active_transactions, and max_header_list_size.

Connection callbacks are:

on_settings($client, $peer_settings, $changed_settings)
on_settings_ack($client, $acked_settings)
on_ping($client, $opaque)
on_ping_ack($client, $opaque)
on_invalid_frame($client, $frame, $lib_error_code)

REQUESTS

request($request, %options) sends a Uniform::HTTP::Request and returns a Unblock::HTTP2::Transaction.

Useful callbacks are:

on_response($transaction, $response)

Final response headers arrived.

on_informational($transaction, $response)

An informational response arrived.

on_body($transaction, $response, $bytes)

A response body chunk arrived.

on_complete($transaction)

The response completed.

on_error($transaction, $error, $error_code)

The transaction failed or its HTTP/2 stream was reset. $error_code can be undefined when there is no HTTP/2 reset code.

on_drain($transaction)

A streaming request body can produce more data.

Set stream_body => 1 to produce the request body with the Transaction write() and end() methods.

CONNECTION CONTROL

The Client also exposes the common connection methods:

is_closed
close_reason
transaction_count
transaction_for_stream_id
local_settings
local_setting
peer_settings
peer_setting
update_settings
settings_pending
ping
draining
drain
goaway
local_goaway
peer_goaway
want_read
want_write
input
output
close

can_open_transaction() reports whether another local request transaction can be opened.

SEE ALSO

Unblock::HTTP2, Unblock::HTTP2::Transaction, Uniform::HTTP::Request

LICENSE

MIT License.