Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: maintain forwards compatibility with REST server streaming #371

Merged
merged 4 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/RequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ public function __construct($baseUri, $restConfigPath)
$this->restConfig = require($restConfigPath);
}

/**
* @param string $path
* @return bool
*/
public function pathExists($path)
{
list($interface, $method) = explode('/', $path);
return isset($this->restConfig['interfaces'][$interface][$method]);
}

/**
* @param string $path
* @param Message $message
Expand Down
8 changes: 8 additions & 0 deletions src/Transport/RestTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use Google\Protobuf\Internal\Message;
use GuzzleHttp\Exception\RequestException;
use Psr\Http\Message\ResponseInterface;
use BadMethodCallException;

/**
* A REST based transport implementation.
Expand Down Expand Up @@ -145,6 +146,7 @@ function (\Exception $ex) {

/**
* {@inheritdoc}
* @throws BadMethodCallException for forwards compatibility with older GAPIC clients
*/
public function startServerStreamingCall(Call $call, array $options)
{
Expand All @@ -153,6 +155,12 @@ public function startServerStreamingCall(Call $call, array $options)
throw new \InvalidArgumentException('A message is required for ServerStreaming calls.');
}

// Maintain forwards compatibility with older GAPIC clients not configured for REST server streaming
// @see https://github.com/googleapis/gax-php/issues/370
if (!$this->requestBuilder->pathExists($call->getMethod())) {
throw new BadMethodCallException('Streaming calls are not supported while using the REST transport');
noahdietz marked this conversation as resolved.
Show resolved Hide resolved
}

$headers = self::buildCommonHeaders($options);
$callOptions = $this->getCallOptions($options);
$request = $this->requestBuilder->build(
Expand Down
2 changes: 2 additions & 0 deletions tests/Tests/Unit/Transport/RestTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ private function getTransport(callable $httpHandler = null, $apiEndpoint = 'http
->getMock();
$requestBuilder->method('build')
->willReturn($request);
$requestBuilder->method('pathExists')
->willReturn(true);

return new RestTransport(
$requestBuilder,
Expand Down