NAME

Google::gRPC::Engine::NGHTTP2 - C/XS nghttp2 HTTP/2 transport engine for Google::gRPC

SYNOPSIS

use Google::gRPC::Engine::NGHTTP2;

my $engine = Google::gRPC::Engine::NGHTTP2->new(
    on_headers      => sub { my ($stream_id, $headers) = @_; ... },
    on_data         => sub { my ($stream_id, $chunk)   = @_; ... },
    on_trailers     => sub { my ($stream_id, $trailers) = @_; ... },
    on_stream_close => sub { my ($stream_id, $code)    = @_; ... },
);

my $stream_id = $engine->submit_request({
    headers    => [ ':method' => 'POST', ':path' => '/pkg.Svc/Call', ... ],
    data       => $framed_bytes,
    end_stream => 1,
});

DESCRIPTION

Google::gRPC::Engine::NGHTTP2 is the high-performance C/XS HTTP/2 framing engine for Google::gRPC, backed by libnghttp2. It is selected automatically by Google::gRPC::Engine when compiled XS bindings are available on the host system, falling back to Google::gRPC::Engine::PP otherwise.

METHODS

new(%callbacks)

my $engine = Google::gRPC::Engine::NGHTTP2->new(
    on_headers      => \&on_headers,
    on_data         => \&on_data,
    on_trailers     => \&on_trailers,
    on_stream_close => \&on_stream_close,
);

Creates a new nghttp2 client session and registers the HTTP/2 frame callbacks. Croaks if the C/XS nghttp2 bindings were not compiled.

set_callbacks(%callbacks)

$engine->set_callbacks(
    on_headers      => \&on_headers,
    on_data         => \&on_data,
    on_trailers     => \&on_trailers,
    on_stream_close => \&on_stream_close,
);

Replaces the registered HTTP/2 event callbacks on an existing session.

submit_request(\%args)

my $stream_id = $engine->submit_request({
    headers    => \@headers,
    data       => $bytes,
    end_stream => 1,
});

Submits an HTTP/2 request with the given flat header arrayref (required), optional framed request body data, and boolean end_stream flag. Returns the assigned HTTP/2 stream ID.

send_ping($cb)

$engine->send_ping(sub { ... });

Queues an HTTP/2 PING frame on the connection for keepalive probing.

SEE ALSO

Google::gRPC, Google::gRPC::Engine, Google::gRPC::Engine::PP

AUTHOR

C.J. Collier <cjac@google.com>

LICENSE

Apache License 2.0