Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX] Restore getUrl support for list of headers
The change of \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl() from cURL to GuzzleHttp the format of the $requestHeaders param was implicitly changed from an array of header strings to an associative array where the key is the header name and the value is either a single or an array of values for that header. This adds back support for the old list of headers format by detecting a non-associative array and converting it to the Guzzle key/value(s) style. At the same time the 'old' way is deprecated. Resolves: #84171 Related: #70056 Releases: master, 8.7 Change-Id: I41b23993957288dfd5294129fa8039aab717461d Reviewed-on: https://review.typo3.org/56046 Tested-by: TYPO3com <no-reply@typo3.com> Reviewed-by: Frank Naegler <frank.naegler@typo3.org> Tested-by: Frank Naegler <frank.naegler@typo3.org> Reviewed-by: Susanne Moog <susanne.moog@typo3.org> Tested-by: Susanne Moog <susanne.moog@typo3.org>
- Loading branch information
1 parent
d8e0000
commit 662fb9a
Showing
5 changed files
with
186 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...AddingGeneralUtilitygetUrlRequestHeadersAsNon-associativeArrayAreDeprecated.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
.. include:: ../../Includes.txt | ||
|
||
========================================================================================================== | ||
Deprecation: #84171 - Adding GeneralUtility::getUrl RequestHeaders as non-associative array are deprecated | ||
========================================================================================================== | ||
|
||
See :issue:`84171` | ||
|
||
Description | ||
=========== | ||
|
||
RequestHeaders passed to getUrl as string (format `Header:Value`) have been deprecated. Associative arrays should be used instead. | ||
|
||
|
||
Impact | ||
====== | ||
|
||
Using `GeneralUtility::getUrl` request headers in a non-associative way will trigger an `E_USER_DEPRECATED` PHP error. | ||
|
||
|
||
Affected Installations | ||
====================== | ||
|
||
All using request headers for `GeneralUtility::getUrl` in a non-associative way. | ||
|
||
|
||
Migration | ||
========= | ||
|
||
Use associative arrays, for example: | ||
|
||
.. code-block:: php | ||
$headers = ['Content-Language: de-DE']; | ||
will become | ||
|
||
.. code-block:: php | ||
$headers = ['Content-Language' => 'de-DE']; | ||
.. index:: PHP-API, NotScanned |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
typo3/sysext/core/Tests/UnitDeprecated/Utility/GeneralUtilityTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
namespace TYPO3\CMS\Core\Tests\UnitDeprecated\Utility; | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
use Prophecy\Argument; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\StreamInterface; | ||
use TYPO3\CMS\Core\Http\RequestFactory; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\TestingFramework\Core\Unit\UnitTestCase; | ||
|
||
/** | ||
* Testcase for the \TYPO3\CMS\Core\Utility\ClientUtility class. | ||
*/ | ||
class GeneralUtilityTest extends UnitTestCase | ||
{ | ||
public function splitHeaderLinesDataProvider(): array | ||
{ | ||
return [ | ||
'one-line, single header' => [ | ||
['Content-Security-Policy:default-src \'self\'; img-src https://*; child-src \'none\';'], | ||
['Content-Security-Policy' => 'default-src \'self\'; img-src https://*; child-src \'none\';'] | ||
], | ||
'one-line, multiple headers' => [ | ||
[ | ||
'Content-Security-Policy:default-src \'self\'; img-src https://*; child-src \'none\';', | ||
'Content-Security-Policy-Report-Only:default-src https:; report-uri /csp-violation-report-endpoint/' | ||
], | ||
[ | ||
'Content-Security-Policy' => 'default-src \'self\'; img-src https://*; child-src \'none\';', | ||
'Content-Security-Policy-Report-Only' => 'default-src https:; report-uri /csp-violation-report-endpoint/' | ||
] | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
* @test | ||
* @dataProvider splitHeaderLinesDataProvider | ||
* @param array $headers | ||
* @param array $expectedHeaders | ||
*/ | ||
public function splitHeaderLines(array $headers, array $expectedHeaders): void | ||
{ | ||
$stream = $this->prophesize(StreamInterface::class); | ||
$response = $this->prophesize(ResponseInterface::class); | ||
$response->getBody()->willReturn($stream); | ||
$requestFactory = $this->prophesize(RequestFactory::class); | ||
$requestFactory->request(Argument::cetera())->willReturn($response); | ||
|
||
GeneralUtility::addInstance(RequestFactory::class, $requestFactory->reveal()); | ||
GeneralUtility::getUrl('http://example.com', 0, $headers); | ||
|
||
$requestFactory->request(Argument::any(), Argument::any(), ['headers' => $expectedHeaders]) | ||
->shouldHaveBeenCalled(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters