function HttpBrowser::getBodyAndExtraHeaders
Return value
array [$body, $headers]
1 call to HttpBrowser::getBodyAndExtraHeaders()
- HttpBrowser::doRequest in vendor/
symfony/ browser-kit/ HttpBrowser.php
File
-
vendor/
symfony/ browser-kit/ HttpBrowser.php, line 65
Class
- HttpBrowser
- An implementation of a browser using the HttpClient component to make real HTTP requests.
Namespace
Symfony\Component\BrowserKitCode
private function getBodyAndExtraHeaders(Request $request, array $headers) : array {
if (\in_array($request->getMethod(), [
'GET',
'HEAD',
]) && !isset($headers['content-type'])) {
return [
'',
[],
];
}
if (!class_exists(AbstractPart::class)) {
throw new LogicException('You cannot pass non-empty bodies as the Mime component is not installed. Try running "composer require symfony/mime".');
}
if (null !== ($content = $request->getContent())) {
if (isset($headers['content-type'])) {
return [
$content,
[],
];
}
$part = new TextPart($content, 'utf-8', 'plain', '8bit');
return [
$part->bodyToString(),
$part->getPreparedHeaders()
->toArray(),
];
}
$fields = $request->getParameters();
if ($uploadedFiles = $this->getUploadedFiles($request->getFiles())) {
$part = new FormDataPart(array_replace_recursive($fields, $uploadedFiles));
return [
$part->bodyToIterable(),
$part->getPreparedHeaders()
->toArray(),
];
}
if (!$fields) {
return [
'',
[],
];
}
array_walk_recursive($fields, $caster = static function (&$v) use (&$caster) {
if (\is_object($v)) {
if ($vars = get_object_vars($v)) {
array_walk_recursive($vars, $caster);
$v = $vars;
}
elseif ($v instanceof \Stringable) {
$v = (string) $v;
}
}
});
return [
http_build_query($fields, '', '&'),
[
'Content-Type' => 'application/x-www-form-urlencoded',
],
];
}