Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7f34c54

Browse filesBrowse files
bug #45814 [HttpClient] Let curl handle Content-Length headers (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpClient] Let curl handle Content-Length headers | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #45709 | License | MIT | Doc PR | - Commits ------- 63f8f1e [HttpClient] Let curl handle Content-Length headers
2 parents c83b2d6 + 63f8f1e commit 7f34c54
Copy full SHA for 7f34c54

File tree

2 files changed

+17
-1
lines changed
Filter options

2 files changed

+17
-1
lines changed

‎src/Symfony/Component/HttpClient/CurlHttpClient.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/CurlHttpClient.php
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,12 @@ public function request(string $method, string $url, array $options = []): Respo
202202
$options['headers'][] = 'Accept-Encoding: gzip'; // Expose only one encoding, some servers mess up when more are provided
203203
}
204204

205+
$hasContentLength = isset($options['normalized_headers']['content-length'][0]);
206+
205207
foreach ($options['headers'] as $header) {
208+
if ($hasContentLength && 0 === stripos($header, 'Content-Length:')) {
209+
continue; // Let curl handle Content-Length headers
210+
}
206211
if (':' === $header[-2] && \strlen($header) - 2 === strpos($header, ': ')) {
207212
// curl requires a special syntax to send empty headers
208213
$curlopts[\CURLOPT_HTTPHEADER][] = substr_replace($header, ';', -2);
@@ -229,7 +234,7 @@ public function request(string $method, string $url, array $options = []): Respo
229234
};
230235
}
231236

232-
if (isset($options['normalized_headers']['content-length'][0])) {
237+
if ($hasContentLength) {
233238
$curlopts[\CURLOPT_INFILESIZE] = substr($options['normalized_headers']['content-length'][0], \strlen('Content-Length: '));
234239
} elseif (!isset($options['normalized_headers']['transfer-encoding'])) {
235240
$curlopts[\CURLOPT_HTTPHEADER][] = 'Transfer-Encoding: chunked'; // Enable chunked request bodies

‎src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,17 @@ public function testNegativeTimeout()
203203
])->getStatusCode());
204204
}
205205

206+
public function testRedirectAfterPost()
207+
{
208+
$client = $this->getHttpClient(__FUNCTION__);
209+
210+
$response = $client->request('POST', 'http://localhost:8057/302/relative', [
211+
'body' => 'abc',
212+
]);
213+
214+
$this->assertSame(200, $response->getStatusCode());
215+
}
216+
206217
public function testNullBody()
207218
{
208219
$client = $this->getHttpClient(__FUNCTION__);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.