Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ro0NL opened this issue Apr 30, 2020 · 1 comment
Closed

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

ro0NL opened this issue Apr 30, 2020 · 1 comment

Comments

@ro0NL
Copy link
Contributor

ro0NL commented Apr 30, 2020

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"
]
@ro0NL
Copy link
Contributor Author

ro0NL commented Apr 30, 2020

i used the following patch:

[$body, $extraHeaders] = $this->getBodyAndExtraHeaders($request, isset($headers['content-type']));
private function getBodyAndExtraHeaders(Request $request, bool $hasContentType = false): array
return [$part->bodyToString(), $hasContentType ? [] : $part->getPreparedHeaders()->toArray()];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants