Google-gRPC
view release on metacpan or search on metacpan
lib/Google/gRPC/Channel.pm view on Meta::CPAN
my $response_class = $opts{response_class};
my $type = $opts{type} || 'unary';
my $timeout_val = $opts{timeout} // $self->timeout;
my $path = '/' . $service . '/' . $method;
my @headers = (
':method' => 'POST',
':path' => $path,
':scheme' => 'https',
':authority' => $self->target,
'content-type' => 'application/grpc',
'te' => 'trailers',
);
if ($self->auth_token) {
push @headers, 'authorization', 'Bearer ' . $self->auth_token;
}
my $deadline_ts;
if (defined $timeout_val) {
my $timeout_sec = Google::gRPC::Deadline::parse_timeout($timeout_val);
lib/Google/gRPC/Client.pm view on Meta::CPAN
}
my $curl = Net::Curl::Easy->new();
my $url = 'https://' . $target_host . '/' . $service . '/' . $method;
$curl->setopt(Net::Curl::Easy::CURLOPT_URL(), $url);
$curl->setopt(Net::Curl::Easy::CURLOPT_POST(), 1);
$curl->setopt(Net::Curl::Easy::CURLOPT_POSTFIELDS(), $framed_payload);
$curl->setopt(Net::Curl::Easy::CURLOPT_POSTFIELDSIZE(), length($framed_payload));
my @headers = (
'content-type: application/grpc',
'te: trailers',
);
if ($self->auth_token) {
push @headers, 'authorization: Bearer ' . $self->auth_token;
}
if (defined $timeout_val) {
my $sec = Google::gRPC::Deadline::parse_timeout($timeout_val);
if (defined $sec) {
my $fmt = Google::gRPC::Deadline::format_grpc_timeout($sec);
t/01-framing.t view on Meta::CPAN
$buf .= substr($packed, 8);
my @f2 = Google::gRPC::Framing::unpack_frame(\$buf);
is(scalar(@f2), 2, 'unpacked 2 frames');
is($f2[0]->{payload}, $p1, 'first frame payload matches');
is($f2[1]->{payload}, $p2, 'second frame payload matches');
};
subtest 'parse trailers' => sub {
my $headers = {
'content-type' => 'application/grpc',
'grpc-status' => '0',
'grpc-message' => 'OK',
};
my $trailers = Google::gRPC::Framing::parse_trailers($headers);
is($trailers->{status}, 0, 'grpc-status is 0');
is($trailers->{message}, 'OK', 'grpc-message is OK');
};
t/02-engine-pp.t view on Meta::CPAN
};
subtest 'Pure-Perl request submission and output generation' => sub {
my $engine = Google::gRPC::Engine::PP->new;
my $stream_id = $engine->submit_request({
headers => [
':method' => 'POST',
':path' => '/test.Service/TestMethod',
':scheme' => 'https',
':authority' => 'localhost:8000',
'content-type' => 'application/grpc',
],
data => 'request payload',
end_stream => 1,
});
ok($stream_id, 'received stream_id from PP engine');
my $out = $engine->get_output;
ok(length($out) > 0, 'generated HTTP/2 output frames');
};
t/03-engine-nghttp2.t view on Meta::CPAN
};
subtest 'C/XS Engine request submission and output generation' => sub {
my $engine = Google::gRPC::Engine::NGHTTP2->new;
my $stream_id = $engine->submit_request({
headers => [
':method' => 'POST',
':path' => '/test.Service/TestMethod',
':scheme' => 'https',
':authority' => 'localhost:8000',
'content-type' => 'application/grpc',
],
data => 'xs request payload',
end_stream => 1,
});
ok($stream_id > 0, 'received positive stream_id from XS engine');
my $out = $engine->get_output;
ok(length($out) > 0, 'generated HTTP/2 output frames from XS engine');
};
t/04-channel-stream.t view on Meta::CPAN
service => 'test.Service',
method => 'TestMethod',
type => 'unary',
on_trailers => sub {
my ($s, $info) = @_;
$status_received = $info->{status};
},
);
$stream->handle_trailers({
'content-type' => 'application/grpc',
'grpc-status' => '0',
'grpc-message' => 'OK',
});
is($status_received, 0, 'trailers status 0 received');
is($stream->status, 0, 'stream status is set to 0');
};
( run in 3.524 seconds using v1.01-cache-2.11-cpan-800906f7e73 )