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 7804522

Browse filesBrowse files
committed
on redirections don't send content related request headers
1 parent 7b43f0f commit 7804522
Copy full SHA for 7804522

File tree

2 files changed

+17
-2
lines changed
Filter options

2 files changed

+17
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/NativeHttpClient.php
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,12 @@ private static function createRedirectResolver(array $options, string $host, ?ar
430430
if ('POST' === $options['method'] || 303 === $info['http_code']) {
431431
$info['http_method'] = $options['method'] = 'HEAD' === $options['method'] ? 'HEAD' : 'GET';
432432
$options['content'] = '';
433-
$options['header'] = array_filter($options['header'], static function ($h) {
433+
$filterContentHeaders = static function ($h) {
434434
return 0 !== stripos($h, 'Content-Length:') && 0 !== stripos($h, 'Content-Type:');
435-
});
435+
};
436+
$options['header'] = array_filter($options['header'], $filterContentHeaders);
437+
$redirectHeaders['no_auth'] = array_filter($redirectHeaders['no_auth'], $filterContentHeaders);
438+
$redirectHeaders['with_auth'] = array_filter($redirectHeaders['with_auth'], $filterContentHeaders);
436439

437440
stream_context_set_option($context, ['http' => $options]);
438441
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,18 @@ public function testFixContentLength()
194194
$this->assertSame(['abc' => 'def', 'REQUEST_METHOD' => 'POST'], $body);
195195
}
196196

197+
public function testDropContentRelatedHeadersWhenFollowingRequestIsUsingGet()
198+
{
199+
$client = $this->getHttpClient(__FUNCTION__);
200+
201+
$response = $client->request('POST', 'http://localhost:8057/302', [
202+
'body' => 'foo',
203+
'headers' => ['Content-Length: 3'],
204+
]);
205+
206+
$this->assertSame(200, $response->getStatusCode());
207+
}
208+
197209
public function testNegativeTimeout()
198210
{
199211
$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.