Skip to content

[BrowserKit] Impossible to specify request content-type #36640

Closed
@ro0NL

Description

@ro0NL

Symfony version(s) affected: 4.4

Description

$headers = $this->getHeaders($request);
[$body, $extraHeaders] = $this->getBodyAndExtraHeaders($request);
$response = $this->client->request($request->getMethod(), $request->getUri(), [
'headers' => array_merge($headers, $extraHeaders),

$extraHeaders includes a content-type, guessed here:

if (null !== $content = $request->getContent()) {
$part = new TextPart($content, 'utf-8', 'plain', '8bit');
return [$part->bodyToString(), $part->getPreparedHeaders()->toArray()];
}

and it's effectively overwriting the existing one in $headers due the array_merge.

dd($headers, $extraHeaders, array_merge($headers, $extraHeaders));
array:6 [
  "user-agent" => "Symfony BrowserKit"
  "content-type" => "application/json"
]
array [
  0 => "Content-Type: text/plain; charset=utf-8"
  1 => "Content-Transfer-Encoding: 8bit"
]
array [
  "user-agent" => "Symfony BrowserKit"
  "content-type" => "application/json"
  0 => "Content-Type: text/plain; charset=utf-8"
  1 => "Content-Transfer-Encoding: 8bit"
]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions