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 63f8f1e

Browse filesBrowse files
[HttpClient] Let curl handle Content-Length headers
1 parent c83b2d6 commit 63f8f1e
Copy full SHA for 63f8f1e

File tree

Expand file treeCollapse file tree

2 files changed

+17
-1
lines changed
Filter options
Expand file treeCollapse file tree

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.