Skip to content

Commit d347895

Browse files
Merge branch '5.4' into 6.0
* 5.4: (21 commits) Add missing license header [Workflow] Catch error when trying to get an uninitialized marking Add missing license header Allow usage of Provider domains if possible Use reference date in reverse transform Fixes #40997 Fix env resolution in lock configuration Fix Symfony not working on SMB share #45990 [Messenger] DoctrineTransportFactory works with notify and decorated PostgreSQL driver [Cache] make LockRegistry use static properties instead of static variables fix: return-path has higher priority for envelope address than from address (fixes #41322) [HttpClient] Fix sending content-length when streaming the body [Console] Header with column max width is now well wrap with separator Fix use_cookies framework session configuration [FrameworkBundle] [Command] Fix `debug:router --no-interaction` error … [Intl] Update the ICU data to 71.1 - 5.4 [Intl] Update the ICU data to 71.1 - 4.4 Add tests to messenger connection get for OraclePlatform [RateLimiter] Adding default empty value [DependencyInjection] Add TaggedIteratorArgument unit tests [Process] Fix Process::getEnv() when setEnv() hasn't been called before ...
2 parents a7930c4 + 0dabec4 commit d347895

File tree

6 files changed

+42
-18
lines changed

6 files changed

+42
-18
lines changed

CurlHttpClient.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,7 @@ public function request(string $method, string $url, array $options = []): Respo
200200
$options['headers'][] = 'Accept-Encoding: gzip'; // Expose only one encoding, some servers mess up when more are provided
201201
}
202202

203-
$hasContentLength = isset($options['normalized_headers']['content-length'][0]);
204-
205-
foreach ($options['headers'] as $i => $header) {
206-
if ($hasContentLength && 0 === stripos($header, 'Content-Length:')) {
207-
// Let curl handle Content-Length headers
208-
unset($options['headers'][$i]);
209-
continue;
210-
}
203+
foreach ($options['headers'] as $header) {
211204
if (':' === $header[-2] && \strlen($header) - 2 === strpos($header, ': ')) {
212205
// curl requires a special syntax to send empty headers
213206
$curlopts[\CURLOPT_HTTPHEADER][] = substr_replace($header, ';', -2);
@@ -234,7 +227,7 @@ public function request(string $method, string $url, array $options = []): Respo
234227
};
235228
}
236229

237-
if ($hasContentLength) {
230+
if (isset($options['normalized_headers']['content-length'][0])) {
238231
$curlopts[\CURLOPT_INFILESIZE] = substr($options['normalized_headers']['content-length'][0], \strlen('Content-Length: '));
239232
} elseif (!isset($options['normalized_headers']['transfer-encoding'])) {
240233
$curlopts[\CURLOPT_HTTPHEADER][] = 'Transfer-Encoding: chunked'; // Enable chunked request bodies
@@ -247,7 +240,7 @@ public function request(string $method, string $url, array $options = []): Respo
247240
$curlopts[\CURLOPT_HTTPHEADER][] = 'Content-Type: application/x-www-form-urlencoded';
248241
}
249242
}
250-
} elseif ('' !== $body || 'POST' === $method || $hasContentLength) {
243+
} elseif ('' !== $body || 'POST' === $method) {
251244
$curlopts[\CURLOPT_POSTFIELDS] = $body;
252245
}
253246

@@ -404,16 +397,26 @@ private static function createRedirectResolver(array $options, string $host): \C
404397
}
405398
}
406399

407-
return static function ($ch, string $location) use ($redirectHeaders) {
400+
return static function ($ch, string $location, bool $noContent) use (&$redirectHeaders) {
408401
try {
409402
$location = self::parseUrl($location);
410403
} catch (InvalidArgumentException $e) {
411404
return null;
412405
}
413406

407+
if ($noContent && $redirectHeaders) {
408+
$filterContentHeaders = static function ($h) {
409+
return 0 !== stripos($h, 'Content-Length:') && 0 !== stripos($h, 'Content-Type:') && 0 !== stripos($h, 'Transfer-Encoding:');
410+
};
411+
$redirectHeaders['no_auth'] = array_filter($redirectHeaders['no_auth'], $filterContentHeaders);
412+
$redirectHeaders['with_auth'] = array_filter($redirectHeaders['with_auth'], $filterContentHeaders);
413+
}
414+
414415
if ($redirectHeaders && $host = parse_url('http:'.$location['authority'], \PHP_URL_HOST)) {
415416
$requestHeaders = $redirectHeaders['host'] === $host ? $redirectHeaders['with_auth'] : $redirectHeaders['no_auth'];
416417
curl_setopt($ch, \CURLOPT_HTTPHEADER, $requestHeaders);
418+
} elseif ($noContent && $redirectHeaders) {
419+
curl_setopt($ch, \CURLOPT_HTTPHEADER, $redirectHeaders['with_auth']);
417420
}
418421

419422
$url = self::parseUrl(curl_getinfo($ch, \CURLINFO_EFFECTIVE_URL));

HttpClientTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
103103
&& (string) \strlen($options['body']) !== substr($h = $options['normalized_headers']['content-length'][0] ?? '', 16)
104104
&& ('' !== $h || '' !== $options['body'])
105105
) {
106-
if (isset($options['normalized_headers']['transfer-encoding'])) {
106+
if ('chunked' === substr($options['normalized_headers']['transfer-encoding'][0] ?? '', \strlen('Transfer-Encoding: '))) {
107107
unset($options['normalized_headers']['transfer-encoding']);
108108
$options['body'] = self::dechunk($options['body']);
109109
}

NativeHttpClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function request(string $method, string $url, array $options = []): Respo
8585

8686
$options['body'] = self::getBodyAsString($options['body']);
8787

88-
if (isset($options['normalized_headers']['transfer-encoding'])) {
88+
if ('chunked' === substr($options['normalized_headers']['transfer-encoding'][0] ?? '', \strlen('Transfer-Encoding: '))) {
8989
unset($options['normalized_headers']['transfer-encoding']);
9090
$options['headers'] = array_merge(...array_values($options['normalized_headers']));
9191
$options['body'] = self::dechunk($options['body']);
@@ -358,7 +358,7 @@ private static function createRedirectResolver(array $options, string $host, ?ar
358358
}
359359
}
360360

361-
return static function (NativeClientState $multi, ?string $location, $context) use ($redirectHeaders, $proxy, &$info, $maxRedirects, $onProgress): ?string {
361+
return static function (NativeClientState $multi, ?string $location, $context) use (&$redirectHeaders, $proxy, &$info, $maxRedirects, $onProgress): ?string {
362362
if (null === $location || $info['http_code'] < 300 || 400 <= $info['http_code']) {
363363
$info['redirect_url'] = null;
364364

@@ -392,7 +392,7 @@ private static function createRedirectResolver(array $options, string $host, ?ar
392392
$info['http_method'] = $options['method'] = 'HEAD' === $options['method'] ? 'HEAD' : 'GET';
393393
$options['content'] = '';
394394
$filterContentHeaders = static function ($h) {
395-
return 0 !== stripos($h, 'Content-Length:') && 0 !== stripos($h, 'Content-Type:');
395+
return 0 !== stripos($h, 'Content-Length:') && 0 !== stripos($h, 'Content-Type:') && 0 !== stripos($h, 'Transfer-Encoding:');
396396
};
397397
$options['header'] = array_filter($options['header'], $filterContentHeaders);
398398
$redirectHeaders['no_auth'] = array_filter($redirectHeaders['no_auth'], $filterContentHeaders);

Response/CurlResponse.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,7 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
404404
if (curl_getinfo($ch, \CURLINFO_REDIRECT_COUNT) === $options['max_redirects']) {
405405
curl_setopt($ch, \CURLOPT_FOLLOWLOCATION, false);
406406
} elseif (303 === $info['http_code'] || ('POST' === $info['http_method'] && \in_array($info['http_code'], [301, 302], true))) {
407-
$info['http_method'] = 'HEAD' === $info['http_method'] ? 'HEAD' : 'GET';
408407
curl_setopt($ch, \CURLOPT_POSTFIELDS, '');
409-
curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, $info['http_method']);
410408
}
411409
}
412410

@@ -425,7 +423,12 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
425423
$info['redirect_url'] = null;
426424

427425
if (300 <= $statusCode && $statusCode < 400 && null !== $location) {
428-
if (null === $info['redirect_url'] = $resolveRedirect($ch, $location)) {
426+
if ($noContent = 303 === $statusCode || ('POST' === $info['http_method'] && \in_array($statusCode, [301, 302], true))) {
427+
$info['http_method'] = 'HEAD' === $info['http_method'] ? 'HEAD' : 'GET';
428+
curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, $info['http_method']);
429+
}
430+
431+
if (null === $info['redirect_url'] = $resolveRedirect($ch, $location, $noContent)) {
429432
$options['max_redirects'] = curl_getinfo($ch, \CURLINFO_REDIRECT_COUNT);
430433
curl_setopt($ch, \CURLOPT_FOLLOWLOCATION, false);
431434
curl_setopt($ch, \CURLOPT_MAXREDIRS, $options['max_redirects']);

Tests/Response/MockResponseTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\HttpClient\Tests\Response;
413

514
use PHPUnit\Framework\TestCase;

Tests/RetryableHttpClientTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\HttpClient\Tests;
413

514
use PHPUnit\Framework\TestCase;

0 commit comments

Comments
 (0)