Skip to content

Commit 2ce90cf

Browse files
authored
fix(HTTP): remove invalid CURLOPT_HTTPHEADER string assignment in CURLRequest (#10695)
1 parent da1a0c7 commit 2ce90cf

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

‎system/HTTP/CURLRequest.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,7 @@ private function applyResponseOptions(array $curlOptions, array $config): array
813813
if ($accept !== '') {
814814
$curlOptions[CURLOPT_ENCODING] = $accept;
815815
} else {
816-
$curlOptions[CURLOPT_ENCODING] = '';
817-
$curlOptions[CURLOPT_HTTPHEADER] = 'Accept-Encoding';
816+
$curlOptions[CURLOPT_ENCODING] = '';
818817
}
819818
}
820819

‎tests/system/HTTP/CURLRequestTest.php‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,6 @@ public function testDecodeContent(): void
673673

674674
public function testDecodeContentWithoutAccept(): void
675675
{
676-
// $this->request->setHeader('Accept-Encoding', 'cobol');
677676
$this->request->request('get', 'http://example.com', [
678677
'decode_content' => true,
679678
]);
@@ -682,8 +681,11 @@ public function testDecodeContentWithoutAccept(): void
682681

683682
$this->assertArrayHasKey(CURLOPT_ENCODING, $options);
684683
$this->assertSame('', $options[CURLOPT_ENCODING]);
685-
$this->assertArrayHasKey(CURLOPT_HTTPHEADER, $options);
686-
$this->assertSame('Accept-Encoding', $options[CURLOPT_HTTPHEADER]);
684+
$this->assertArrayNotHasKey(CURLOPT_HTTPHEADER, $options);
685+
686+
// Verify that curl_setopt_array accepts the options without TypeError
687+
$handle = curl_init();
688+
$this->assertTrue(curl_setopt_array($handle, $options));
687689
}
688690

689691
public function testAllowRedirectsOptionFalse(): void
@@ -1629,7 +1631,7 @@ public function testSetCURLOptions(): void
16291631
// Test Response Options (decode_content / http_errors)
16301632
$options12 = $invoker([], ['decode_content' => true]);
16311633
$this->assertSame('', $options12[CURLOPT_ENCODING]);
1632-
$this->assertSame('Accept-Encoding', $options12[CURLOPT_HTTPHEADER]);
1634+
$this->assertArrayNotHasKey(CURLOPT_HTTPHEADER, $options12);
16331635

16341636
// Test Protocol/Misc/Client Options
16351637
$options13 = $invoker([], [

‎user_guide_src/source/changelogs/v4.7.6.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ Bugs Fixed
9999
- **HTTP:** Fixed a bug in ``ContentSecurityPolicy`` where a numeric source such as ``'0'`` threw a ``TypeError``, and a space-separated directive string in ``Config\\ContentSecurityPolicy`` was emitted as one unquoted source.
100100
- **HTTP:** Fixed a regression in v4.7.0 where calling ``ContentSecurityPolicy::reportOnly()`` after the policy was created did not apply to array sources from ``Config\\ContentSecurityPolicy``, so they stayed in the enforced ``Content-Security-Policy`` header alongside the ``Content-Security-Policy-Report-Only`` header.
101101
- **HTTP:** Fixed a bug in ``ContentSecurityPolicy::setDefaultSrc()`` where passing an array of URIs resulted in an invalid ``'Array'`` directive.
102+
- **HTTP:** Fixed a bug where ``CURLRequest`` threw a ``TypeError`` when ``decode_content`` was enabled without custom request headers because ``CURLOPT_HTTPHEADER`` was set to a string instead of an array.
102103
- **HTTP:** Fixed a bug where ``IncomingRequest`` did not read the request body when PHP's ``post_max_size`` was set to ``0`` or ``-1`` (unlimited).
103104
- **HTTP:** Fixed a bug where ``IncomingRequest::isSecure()`` did not recognize ``https`` in the ``X-Forwarded-Proto`` header from a trusted proxy when the value contained uppercase letters or surrounding whitespace, or was represented as a single-element array.
104105
- **HTTP:** Fixed a bug where ``Negotiate::media()`` threw an ``ErrorException`` when the ``Accept`` header contained a value without a subtype, such as ``json`` or an empty list element. Such values are now ignored.

0 commit comments

Comments
 (0)