Skip to content

Commit c69fed8

Browse files
Merge branch '4.4' into 5.4
* 4.4: [Workflow] Catch error when trying to get an uninitialized marking Add missing license header Use reference date in reverse transform Fixes #40997 Fix env resolution in lock configuration Fix Symfony not working on SMB share #45990 [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 [DependencyInjection] Add TaggedIteratorArgument unit tests
2 parents 88b6909 + bad7c32 commit c69fed8

File tree

5 files changed

+33
-18
lines changed

5 files changed

+33
-18
lines changed

CurlHttpClient.php

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

208-
$hasContentLength = isset($options['normalized_headers']['content-length'][0]);
209-
210-
foreach ($options['headers'] as $i => $header) {
211-
if ($hasContentLength && 0 === stripos($header, 'Content-Length:')) {
212-
// Let curl handle Content-Length headers
213-
unset($options['headers'][$i]);
214-
continue;
215-
}
208+
foreach ($options['headers'] as $header) {
216209
if (':' === $header[-2] && \strlen($header) - 2 === strpos($header, ': ')) {
217210
// curl requires a special syntax to send empty headers
218211
$curlopts[\CURLOPT_HTTPHEADER][] = substr_replace($header, ';', -2);
@@ -239,7 +232,7 @@ public function request(string $method, string $url, array $options = []): Respo
239232
};
240233
}
241234

242-
if ($hasContentLength) {
235+
if (isset($options['normalized_headers']['content-length'][0])) {
243236
$curlopts[\CURLOPT_INFILESIZE] = substr($options['normalized_headers']['content-length'][0], \strlen('Content-Length: '));
244237
} elseif (!isset($options['normalized_headers']['transfer-encoding'])) {
245238
$curlopts[\CURLOPT_HTTPHEADER][] = 'Transfer-Encoding: chunked'; // Enable chunked request bodies
@@ -252,7 +245,7 @@ public function request(string $method, string $url, array $options = []): Respo
252245
$curlopts[\CURLOPT_HTTPHEADER][] = 'Content-Type: application/x-www-form-urlencoded';
253246
}
254247
}
255-
} elseif ('' !== $body || 'POST' === $method || $hasContentLength) {
248+
} elseif ('' !== $body || 'POST' === $method) {
256249
$curlopts[\CURLOPT_POSTFIELDS] = $body;
257250
}
258251

@@ -411,16 +404,26 @@ private static function createRedirectResolver(array $options, string $host): \C
411404
}
412405
}
413406

414-
return static function ($ch, string $location) use ($redirectHeaders) {
407+
return static function ($ch, string $location, bool $noContent) use (&$redirectHeaders) {
415408
try {
416409
$location = self::parseUrl($location);
417410
} catch (InvalidArgumentException $e) {
418411
return null;
419412
}
420413

414+
if ($noContent && $redirectHeaders) {
415+
$filterContentHeaders = static function ($h) {
416+
return 0 !== stripos($h, 'Content-Length:') && 0 !== stripos($h, 'Content-Type:') && 0 !== stripos($h, 'Transfer-Encoding:');
417+
};
418+
$redirectHeaders['no_auth'] = array_filter($redirectHeaders['no_auth'], $filterContentHeaders);
419+
$redirectHeaders['with_auth'] = array_filter($redirectHeaders['with_auth'], $filterContentHeaders);
420+
}
421+
421422
if ($redirectHeaders && $host = parse_url('http:'.$location['authority'], \PHP_URL_HOST)) {
422423
$requestHeaders = $redirectHeaders['host'] === $host ? $redirectHeaders['with_auth'] : $redirectHeaders['no_auth'];
423424
curl_setopt($ch, \CURLOPT_HTTPHEADER, $requestHeaders);
425+
} elseif ($noContent && $redirectHeaders) {
426+
curl_setopt($ch, \CURLOPT_HTTPHEADER, $redirectHeaders['with_auth']);
424427
}
425428

426429
$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
@@ -86,7 +86,7 @@ public function request(string $method, string $url, array $options = []): Respo
8686

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

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

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

@@ -400,7 +400,7 @@ private static function createRedirectResolver(array $options, string $host, ?ar
400400
$info['http_method'] = $options['method'] = 'HEAD' === $options['method'] ? 'HEAD' : 'GET';
401401
$options['content'] = '';
402402
$filterContentHeaders = static function ($h) {
403-
return 0 !== stripos($h, 'Content-Length:') && 0 !== stripos($h, 'Content-Type:');
403+
return 0 !== stripos($h, 'Content-Length:') && 0 !== stripos($h, 'Content-Type:') && 0 !== stripos($h, 'Transfer-Encoding:');
404404
};
405405
$options['header'] = array_filter($options['header'], $filterContentHeaders);
406406
$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
@@ -407,9 +407,7 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
407407
if (curl_getinfo($ch, \CURLINFO_REDIRECT_COUNT) === $options['max_redirects']) {
408408
curl_setopt($ch, \CURLOPT_FOLLOWLOCATION, false);
409409
} elseif (303 === $info['http_code'] || ('POST' === $info['http_method'] && \in_array($info['http_code'], [301, 302], true))) {
410-
$info['http_method'] = 'HEAD' === $info['http_method'] ? 'HEAD' : 'GET';
411410
curl_setopt($ch, \CURLOPT_POSTFIELDS, '');
412-
curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, $info['http_method']);
413411
}
414412
}
415413

@@ -428,7 +426,12 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
428426
$info['redirect_url'] = null;
429427

430428
if (300 <= $statusCode && $statusCode < 400 && null !== $location) {
431-
if (null === $info['redirect_url'] = $resolveRedirect($ch, $location)) {
429+
if ($noContent = 303 === $statusCode || ('POST' === $info['http_method'] && \in_array($statusCode, [301, 302], true))) {
430+
$info['http_method'] = 'HEAD' === $info['http_method'] ? 'HEAD' : 'GET';
431+
curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, $info['http_method']);
432+
}
433+
434+
if (null === $info['redirect_url'] = $resolveRedirect($ch, $location, $noContent)) {
432435
$options['max_redirects'] = curl_getinfo($ch, \CURLINFO_REDIRECT_COUNT);
433436
curl_setopt($ch, \CURLOPT_FOLLOWLOCATION, false);
434437
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;

0 commit comments

Comments
 (0)