Bug #88871
Updated by Frank Nägler over 5 years ago
Guzzle has the possibility to push custom middleware handler during client initialization.
The T3 core RequestFactory has the protected method "getClient()" and transfers the TYPO3_CONF_VARS HTTP configuration to the Guzzle client.
Guzzle Middleware handler: https://guzzle.readthedocs.io/en/latest/handlers-and-middleware.html#middleware
+Current state:+
If you define the handler in $GLOBALS['TYPO3_CONF_VARS']['HTTP']['handler'], the default handler stack of guzzle gets overwritten. You are not able to create the default HandlerStack before the Guzzle Client get's initialized.
+Should be:+
If the configuration $GLOBALS['TYPO3_CONF_VARS']['HTTP']['handler'] is set, the request factory creates the default Guzzle handler stack and pushs the additional handler to the guzzle client.
*Code example for the T3 Core RequestFactory:*
<pre><code class="php">
/**
* Creates the client to do requests
* @return ClientInterface
*/
protected function getClient(): ClientInterface
{
$httpOptions = $GLOBALS['TYPO3_CONF_VARS']['HTTP'];
$httpOptions['verify'] = filter_var($httpOptions['verify'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ?? $httpOptions['verify'];
if (isset($GLOBALS['TYPO3_CONF_VARS']['HTTP']['handler']) && is_array($GLOBALS['TYPO3_CONF_VARS']['HTTP']['handler'])) {
$stack = \GuzzleHttp\HandlerStack::create();
foreach ($GLOBALS['TYPO3_CONF_VARS']['HTTP']['handler'] ?? [] as $handler) {
$stack->push($handler);
}
$httpOptions['handler'] = $stack;
}
return GeneralUtility::makeInstance(Client::class, $httpOptions);
}
</code></pre>
*EDIT:* Demo Extension is available on GitHub: https://github.com/JBlocks/t3guzzlelog