Skip to content

Commit

Permalink
fix: maintain forwards compatibility with REST server streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Jan 26, 2022
1 parent 381f91a commit 4c36e8b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
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');
}

$headers = self::buildCommonHeaders($options);
$callOptions = $this->getCallOptions($options);
$request = $this->requestBuilder->build(
Expand Down

0 comments on commit 4c36e8b

Please sign in to comment.