Skip to content

Commit 51c8cd4

Browse files
Merge branch '4.4' into 5.0
* 4.4: (27 commits) [Serializer] minor cleanup fix merge Run PHP 8 as 7.4.99 Remove calls to deprecated ReflectionParameter::getClass(). [VarDumper] fix PHP 8 support Add php 8 to travis. [Cache] Accessing undefined constants raises an Error in php8 [Cache] allow DBAL v3 Skip Doctrine DBAL on php 8 until we have a compatible version. [DomCrawler] Catch expected ValueError. Made method signatures compatible with their corresponding traits. [ErrorHandler] Apply php8 fixes from Debug component. [DomCrawler] Catch expected ValueError. [Validator] Catch expected ValueError. [VarDumper] ReflectionFunction::isDisabled() is deprecated. [BrowserKit] Raw body with custom Content-Type header [PropertyAccess] Parse php 8 TypeErrors correctly. [Intl] Fix call to ReflectionProperty::getValue() for static properties. [HttpKernel] Prevent calling method_exists() with non-string values. Fix wrong roles comparison ...
2 parents 5822f5a + f533106 commit 51c8cd4

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

HttpBrowser.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public function __construct(HttpClientInterface $client = null, History $history
3939
parent::__construct([], $history, $cookieJar);
4040
}
4141

42-
protected function doRequest($request): Response
42+
protected function doRequest(Request $request): Response
4343
{
4444
$headers = $this->getHeaders($request);
45-
[$body, $extraHeaders] = $this->getBodyAndExtraHeaders($request);
45+
[$body, $extraHeaders] = $this->getBodyAndExtraHeaders($request, $headers);
4646

4747
$response = $this->client->request($request->getMethod(), $request->getUri(), [
4848
'headers' => array_merge($headers, $extraHeaders),
@@ -56,7 +56,7 @@ protected function doRequest($request): Response
5656
/**
5757
* @return array [$body, $headers]
5858
*/
59-
private function getBodyAndExtraHeaders(Request $request): array
59+
private function getBodyAndExtraHeaders(Request $request, array $headers): array
6060
{
6161
if (\in_array($request->getMethod(), ['GET', 'HEAD'])) {
6262
return ['', []];
@@ -67,6 +67,10 @@ private function getBodyAndExtraHeaders(Request $request): array
6767
}
6868

6969
if (null !== $content = $request->getContent()) {
70+
if (isset($headers['content-type'])) {
71+
return [$content, []];
72+
}
73+
7074
$part = new TextPart($content, 'utf-8', 'plain', '8bit');
7175

7276
return [$part->bodyToString(), $part->getPreparedHeaders()->toArray()];

Tests/HttpBrowserTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ public function validContentTypes()
5959
['POST', 'http://example.com/', [], [], [], 'content'],
6060
['POST', 'http://example.com/', ['headers' => $defaultHeaders + ['Content-Type: text/plain; charset=utf-8', 'Content-Transfer-Encoding: 8bit'], 'body' => 'content', 'max_redirects' => 0]],
6161
];
62+
yield 'POST JSON' => [
63+
['POST', 'http://example.com/', [], [], ['CONTENT_TYPE' => 'application/json'], '["content"]'],
64+
['POST', 'http://example.com/', ['headers' => $defaultHeaders + ['content-type' => 'application/json'], 'body' => '["content"]', 'max_redirects' => 0]],
65+
];
6266
}
6367

6468
public function testMultiPartRequestWithSingleFile()

0 commit comments

Comments
 (0)