Bug #88871

RequestFactory respects Guzzle Middleware/Handler configuration from TYPO3_CONF_VARS

Added by Joerg Boesche 4 months ago. Updated 4 months ago.

Status:
Resolved
Priority:
Must have
Assignee:
Category:
Miscellaneous
Target version:
Start date:
2019-07-31
Due date:
% Done:

100%

TYPO3 Version:
8
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

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:

/**
     * 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);
    }

EDIT: Demo Extension is available on GitHub: https://github.com/JBlocks/t3guzzlelog

Associated revisions

Revision 37bf2b52 (diff)
Added by Frank Naegler 4 months ago

[FEATURE] Allow array of handlers in RequestFactory

Guzzle has the possibility to push custom middleware handlers during
client initialization. With this patch it is now possible to define own
handlers as an array of callables in $GLOBALS['TYPO3_CONF_VARS']['HTTP']['handler'].
The RequestFactory builds a HandlerStack from that array
and injects it into the created client.

Resolves: #88871
Releases: master
Change-Id: I62cb9c58c9ef7f8ce66255eb34b3a0953666cbc2
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61407
Tested-by: TYPO3com <>
Tested-by: Andreas Fernandez <>
Tested-by: Anja Leichsenring <>
Reviewed-by: Andreas Fernandez <>
Reviewed-by: Anja Leichsenring <>

History

#1 Updated by Joerg Boesche 4 months ago

  • Description updated (diff)

#2 Updated by Frank Naegler 4 months ago

  • Category set to Miscellaneous
  • Status changed from New to Accepted
  • Assignee set to Frank Naegler

#3 Updated by Frank Naegler 4 months ago

  • Tracker changed from Feature to Bug
  • TYPO3 Version set to 8

#4 Updated by Gerrit Code Review 4 months ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61407

#5 Updated by Gerrit Code Review 4 months ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61407

#6 Updated by Frank Naegler 4 months ago

  • Description updated (diff)

#7 Updated by Gerrit Code Review 4 months ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61407

#8 Updated by Gerrit Code Review 4 months ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61407

#9 Updated by Gerrit Code Review 4 months ago

Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61407

#10 Updated by Gerrit Code Review 4 months ago

Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61407

#11 Updated by Gerrit Code Review 4 months ago

Patch set 7 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61407

#12 Updated by Frank Naegler 4 months ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

Also available in: Atom PDF