Skip to content

Commit

Permalink
bug #54517 [HttpClient] Let curl handle transfer encoding (michaelhue)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

[HttpClient] Let curl handle transfer encoding

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #54516, Fix #54491
| License       | MIT

Removes the `Transfer-Encoding: chunked` header that is added for chunked request bodies. This will allow curl to handle the transfer encoding and set appropriate headers based on the HTTP protocol version it negotiated with the server, since HTTP/2 does not support chunked transfer encoding.

Commits
-------

69a7867 [HttpClient] Let curl handle transfer encoding
  • Loading branch information
nicolas-grekas committed Apr 8, 2024
2 parents 49e9184 + 69a7867 commit de1409e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Symfony/Component/HttpClient/CurlHttpClient.php
Expand Up @@ -246,9 +246,8 @@ public function request(string $method, string $url, array $options = []): Respo

if (isset($options['normalized_headers']['content-length'][0])) {
$curlopts[\CURLOPT_INFILESIZE] = (int) substr($options['normalized_headers']['content-length'][0], \strlen('Content-Length: '));
}
if (!isset($options['normalized_headers']['transfer-encoding'])) {
$curlopts[\CURLOPT_HTTPHEADER][] = 'Transfer-Encoding:'.(isset($curlopts[\CURLOPT_INFILESIZE]) ? '' : ' chunked');
} elseif (!isset($options['normalized_headers']['transfer-encoding'])) {
$curlopts[\CURLOPT_INFILESIZE] = -1;
}

if ('POST' !== $method) {
Expand Down

0 comments on commit de1409e

Please sign in to comment.