Skip to content
This repository was archived by the owner on Apr 20, 2021. It is now read-only.

Commit a6db7c0

Browse files
committed
fix: don't set the Accept header by default
1 parent 78b29a4 commit a6db7c0

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

src/HttpCall/Request/BrowserKit.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ public function send($method, $url, $parameters = [], $files = [], $content = nu
6868
$client = $this->mink->getSession()->getDriver()->getClient();
6969

7070
$client->followRedirects(false);
71+
72+
// Workaround for https://github.com/symfony/symfony/issues/33393: prevent a default Accept header to be set
73+
if (!isset($headers['HTTP_ACCEPT']) && '' === $client->getServerParameter('HTTP_ACCEPT')) {
74+
$headers['HTTP_ACCEPT'] = null;
75+
}
76+
7177
$client->request($method, $url, $parameters, $files, $headers, $content);
7278
$client->followRedirects(true);
7379
$this->resetHttpHeaders();
@@ -78,11 +84,15 @@ public function send($method, $url, $parameters = [], $files = [], $content = nu
7884
public function setHttpHeader($name, $value)
7985
{
8086
$client = $this->mink->getSession()->getDriver()->getClient();
81-
// Goutte\Client
8287
if (method_exists($client, 'setHeader')) {
88+
/**
89+
* @var \Goutte\Client $client
90+
*/
8391
$client->setHeader($name, $value);
8492
} else {
85-
// Symfony\Component\BrowserKit\Client
93+
/**
94+
* @var \Symfony\Component\BrowserKit\HttpBrowser $client
95+
*/
8696

8797
/* taken from Behat\Mink\Driver\BrowserKitDriver::setRequestHeader */
8898
$contentHeaders = ['CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true];

tests/features/rest.feature

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ Feature: Testing RESTContext
9797
Congratulations, you've correctly set up your apache environment.
9898
"""
9999

100-
@>php5.5
100+
Scenario: Accept header should not be set by dfault
101+
When I send a GET request to "/rest/index.php"
102+
Then I should not see "HTTP_ACCEPT"
103+
104+
@>php5.5
101105
Scenario: Set content headers in POST request
102106
When I add "Content-Type" header equal to "xxx"
103107
When I send a "POST" request to "rest/index.php" with body:

tests/fixtures/www/rest/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
You have sent a <?php print $_SERVER['REQUEST_METHOD']; ?> request.
1919

2020
<?php print sizeof($_SERVER); ?> header(s) received.
21-
<?php foreach($_SERVER as $key => $value): ?>
21+
<?php foreach(array_filter($_SERVER) as $key => $value): ?>
2222
<br /><?php print $key ?> : <?php print $value; ?>
2323
<?php endforeach; ?>
2424

0 commit comments

Comments
 (0)