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 d2dd92b

Browse filesBrowse files
azhurbfabpot
authored andcommitted
[BrowserKit] Raw body with custom Content-Type header
1 parent 94e8c42 commit d2dd92b
Copy full SHA for d2dd92b

File tree

2 files changed

+13
-2
lines changed
Filter options

2 files changed

+13
-2
lines changed

‎src/Symfony/Component/BrowserKit/HttpBrowser.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/BrowserKit/HttpBrowser.php
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ public function __construct(HttpClientInterface $client = null, History $history
3939
parent::__construct([], $history, $cookieJar);
4040
}
4141

42+
/**
43+
* @param Request $request
44+
*/
4245
protected function doRequest($request): Response
4346
{
4447
$headers = $this->getHeaders($request);
45-
[$body, $extraHeaders] = $this->getBodyAndExtraHeaders($request);
48+
[$body, $extraHeaders] = $this->getBodyAndExtraHeaders($request, $headers);
4649

4750
$response = $this->client->request($request->getMethod(), $request->getUri(), [
4851
'headers' => array_merge($headers, $extraHeaders),
@@ -56,7 +59,7 @@ protected function doRequest($request): Response
5659
/**
5760
* @return array [$body, $headers]
5861
*/
59-
private function getBodyAndExtraHeaders(Request $request): array
62+
private function getBodyAndExtraHeaders(Request $request, array $headers): array
6063
{
6164
if (\in_array($request->getMethod(), ['GET', 'HEAD'])) {
6265
return ['', []];
@@ -67,6 +70,10 @@ private function getBodyAndExtraHeaders(Request $request): array
6770
}
6871

6972
if (null !== $content = $request->getContent()) {
73+
if (isset($headers['content-type'])) {
74+
return [$content, []];
75+
}
76+
7077
$part = new TextPart($content, 'utf-8', 'plain', '8bit');
7178

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

‎src/Symfony/Component/BrowserKit/Tests/HttpBrowserTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/BrowserKit/Tests/HttpBrowserTest.php
+4Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.