From 48eebfc77bd4957c5439566a4d619d41ba05926e Mon Sep 17 00:00:00 2001 From: geoffrey Date: Mon, 16 Sep 2019 21:06:04 +0200 Subject: [PATCH] Add default value for Accept header --- src/Symfony/Component/HttpClient/HttpClientTrait.php | 4 ++++ .../Component/HttpClient/Tests/HttpClientTraitTest.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpClient/HttpClientTrait.php b/src/Symfony/Component/HttpClient/HttpClientTrait.php index 1c5e4578c7..9fc37f7299 100644 --- a/src/Symfony/Component/HttpClient/HttpClientTrait.php +++ b/src/Symfony/Component/HttpClient/HttpClientTrait.php @@ -56,6 +56,10 @@ trait HttpClientTrait } } + if (!isset($options['normalized_headers']['accept'])) { + $options['normalized_headers']['accept'] = [$options['headers'][] = 'Accept: *']; + } + if (isset($options['body'])) { $options['body'] = self::normalizeBody($options['body']); } diff --git a/src/Symfony/Component/HttpClient/Tests/HttpClientTraitTest.php b/src/Symfony/Component/HttpClient/Tests/HttpClientTraitTest.php index 7971b79143..559f2b6227 100644 --- a/src/Symfony/Component/HttpClient/Tests/HttpClientTraitTest.php +++ b/src/Symfony/Component/HttpClient/Tests/HttpClientTraitTest.php @@ -172,7 +172,7 @@ class HttpClientTraitTest extends TestCase public function testAuthBearerOption() { [, $options] = self::prepareRequest('POST', 'http://example.com', ['auth_bearer' => 'foobar'], HttpClientInterface::OPTIONS_DEFAULTS); - $this->assertSame(['Authorization: Bearer foobar'], $options['headers']); + $this->assertSame(['Accept: *', 'Authorization: Bearer foobar'], $options['headers']); $this->assertSame(['Authorization: Bearer foobar'], $options['normalized_headers']['authorization']); }