Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit231621b

Browse files
jderussenicolas-grekas
authored andcommitted
[HttpClient] Handle requests with null body
1 parent65e6faa commit231621b

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
trait HttpClientTrait
2424
{
2525
privatestatic$CHUNK_SIZE =16372;
26+
privatestatic$emptyDefaults;
2627

2728
/**
2829
* Validates and normalizes method, URL and options, and merges them with defaults.
@@ -40,6 +41,16 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
4041
}
4142
}
4243

44+
if (null ===self::$emptyDefaults ??$method) {
45+
self::$emptyDefaults = [];
46+
47+
foreach ($defaultOptionsas$k =>$v) {
48+
if (null !==$v) {
49+
self::$emptyDefaults[$k] =$v;
50+
}
51+
}
52+
}
53+
4354
$options =self::mergeDefaultOptions($options,$defaultOptions,$allowExtraOptions);
4455

4556
$buffer =$options['buffer'] ??true;
@@ -189,6 +200,16 @@ private static function mergeDefaultOptions(array $options, array $defaultOption
189200

190201
$options +=$defaultOptions;
191202

203+
if (null ===self::$emptyDefaults) {
204+
self::$emptyDefaults = [];
205+
}
206+
207+
foreach (self::$emptyDefaultsas$k =>$v) {
208+
if (!isset($options[$k])) {
209+
$options[$k] =$v;
210+
}
211+
}
212+
192213
if (isset($defaultOptions['extra'])) {
193214
$options['extra'] +=$defaultOptions['extra'];
194215
}
@@ -221,9 +242,9 @@ private static function mergeDefaultOptions(array $options, array $defaultOption
221242

222243
$alternatives = [];
223244

224-
foreach ($defaultOptionsas$key =>$v) {
225-
if (levenshtein($name,$key) <=\strlen($name) /3 ||str_contains($key,$name)) {
226-
$alternatives[] =$key;
245+
foreach ($defaultOptionsas$k =>$v) {
246+
if (levenshtein($name,$k) <=\strlen($name) /3 ||str_contains($k,$name)) {
247+
$alternatives[] =$k;
227248
}
228249
}
229250

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ public function testHandleIsReinitOnReset()
148148
self::assertNotSame($initialShareId,$clientState->share);
149149
}
150150

151+
publicfunctiontestNullBody()
152+
{
153+
$httpClient =$this->getHttpClient(__FUNCTION__);
154+
155+
$httpClient->request('POST','http://localhost:8057/post', [
156+
'body' =>null,
157+
]);
158+
159+
$this->expectNotToPerformAssertions();
160+
}
161+
151162
publicfunctiontestProcessAfterReset()
152163
{
153164
$client =$this->getHttpClient(__FUNCTION__);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp