throwUnsupportedException(); } /** * {@inheritdoc} * @return never * @throws \BadMethodCallException */ public function startServerStreamingCall(Call $call, array $options) { $this->throwUnsupportedException(); } /** * {@inheritdoc} * @return never * @throws \BadMethodCallException */ public function startBidiStreamingCall(Call $call, array $options) { $this->throwUnsupportedException(); } /** * {@inheritdoc} */ public function close() { // Nothing to do. } /** * @param array $options * @return array */ private static function buildCommonHeaders(array $options) { $headers = $options['headers'] ?? []; if (!\is_array($headers)) { throw new \InvalidArgumentException('The "headers" option must be an array'); } // If not already set, add an auth header to the request if (!isset($headers['Authorization']) && isset($options['credentialsWrapper'])) { $credentialsWrapper = $options['credentialsWrapper']; $audience = $options['audience'] ?? null; $callback = $credentialsWrapper->getAuthorizationHeaderCallback($audience); // Prevent unexpected behavior, as the authorization header callback // uses lowercase "authorization" unset($headers['authorization']); // Mitigate scenario where InsecureCredentialsWrapper returns null. $authHeaders = empty($callback) ? [] : $callback(); if (!\is_array($authHeaders)) { throw new \UnexpectedValueException('Expected array response from authorization header callback'); } $headers += $authHeaders; } return $headers; } /** * @return callable * @throws ValidationException */ private static function buildHttpHandlerAsync() { try { return [HttpHandlerFactory::build(), 'async']; } catch (Exception $ex) { throw new ValidationException("Failed to build HttpHandler", $ex->getCode(), $ex); } } /** * Set the path to a client certificate. * * @param callable $clientCertSource */ private function configureMtlsChannel(callable $clientCertSource) { $this->clientCertSource = $clientCertSource; } /** * @return never * @throws \BadMethodCallException */ private function throwUnsupportedException() { throw new \BadMethodCallException("Streaming calls are not supported while using the {$this->transportName} transport."); } private static function loadClientCertSource(callable $clientCertSource) { $certFile = \tempnam(\sys_get_temp_dir(), 'cert'); $keyFile = \tempnam(\sys_get_temp_dir(), 'key'); list($cert, $key) = \call_user_func($clientCertSource); \file_put_contents($certFile, $cert); \file_put_contents($keyFile, $key); // the key and the cert are returned in one temporary file return [$certFile, $keyFile]; } }