Skip to content

Commit

Permalink
Address TODO about debugging in external HTTP client
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcdawkins committed Dec 27, 2024
1 parent e231cbd commit b5decef
Showing 1 changed file with 19 additions and 31 deletions.
50 changes: 19 additions & 31 deletions src/Service/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Platformsh\Cli\Service;

use GuzzleHttp\HandlerStack;
use Symfony\Component\Filesystem\Filesystem;
use GuzzleHttp\Exception\RequestException;
use Platformsh\Client\Model\Integration;
Expand Down Expand Up @@ -476,36 +477,6 @@ private function tokenFromSession(SessionInterface $session): ?AccessToken
return new AccessToken($tokenData);
}

/**
* Returns configuration options for instantiating a Guzzle HTTP client.
*
* @see Client::__construct()
*
* @return array<string, mixed>
*/
public function getGuzzleOptions(): array
{
$options = [
'headers' => ['User-Agent' => $this->config->getUserAgent()],
'debug' => false,
'verify' => $this->config->getBool('api.skip_ssl') ? false : $this->caBundlePath(),
'proxy' => $this->guzzleProxyConfig(),
'timeout' => $this->config->getInt('api.default_timeout'),
];

// TODO provide this as a middleware
// if ($this->output->isVeryVerbose()) {
// $options['defaults']['subscribers'][] = new GuzzleDebugMiddleware($this->output, $this->config->getBool('api.debug'));
// }

if (extension_loaded('zlib')) {
$options['decode_content'] = true;
$options['headers']['Accept-Encoding'] = 'gzip';
}

return $options;
}

/**
* Returns proxy config in the format expected by Guzzle.
*
Expand Down Expand Up @@ -1260,7 +1231,24 @@ public function getHttpClient(): ClientInterface
*/
public function getExternalHttpClient(): ClientInterface
{
return new Client($this->getGuzzleOptions());
$options = [
'headers' => ['User-Agent' => $this->config->getUserAgent()],
'debug' => false,
'verify' => $this->config->getBool('api.skip_ssl') ? false : $this->caBundlePath(),
'proxy' => $this->guzzleProxyConfig(),
'timeout' => $this->config->getInt('api.default_timeout'),
];

if (extension_loaded('zlib')) {
$options['decode_content'] = true;
$options['headers']['Accept-Encoding'] = 'gzip';
}

$stack = HandlerStack::create();
$stack->push(new GuzzleDebugMiddleware($this->output, $this->config->getBool('api.debug')));
$options['handler'] = $stack;

return new Client($options);
}

/**
Expand Down

0 comments on commit b5decef

Please sign in to comment.