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

fix: don't set the Accept header by default #293

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/HttpCall/Request/BrowserKit.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ public function send($method, $url, $parameters = [], $files = [], $content = nu
$client = $this->mink->getSession()->getDriver()->getClient();

$client->followRedirects(false);

// Workaround for https://github.com/symfony/symfony/issues/33393: prevent a default Accept header to be set
if (!isset($headers['HTTP_ACCEPT']) && '' === $client->getServerParameter('HTTP_ACCEPT')) {
$headers['HTTP_ACCEPT'] = null;
}

$client->request($method, $url, $parameters, $files, $headers, $content);
$client->followRedirects(true);
$this->resetHttpHeaders();
Expand All @@ -78,11 +84,15 @@ public function send($method, $url, $parameters = [], $files = [], $content = nu
public function setHttpHeader($name, $value)
{
$client = $this->mink->getSession()->getDriver()->getClient();
// Goutte\Client
if (method_exists($client, 'setHeader')) {
/**
* @var \Goutte\Client $client
*/
$client->setHeader($name, $value);
} else {
// Symfony\Component\BrowserKit\Client
/**
* @var \Symfony\Component\BrowserKit\HttpBrowser $client
*/

/* taken from Behat\Mink\Driver\BrowserKitDriver::setRequestHeader */
$contentHeaders = ['CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true];
Expand Down
6 changes: 5 additions & 1 deletion tests/features/rest.feature
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ Feature: Testing RESTContext
Congratulations, you've correctly set up your apache environment.
"""

@>php5.5
Scenario: Accept header should not be set by dfault
When I send a GET request to "/rest/index.php"
Then I should not see "HTTP_ACCEPT"

@>php5.5
Scenario: Set content headers in POST request
When I add "Content-Type" header equal to "xxx"
When I send a "POST" request to "rest/index.php" with body:
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/www/rest/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
You have sent a <?php print $_SERVER['REQUEST_METHOD']; ?> request.

<?php print sizeof($_SERVER); ?> header(s) received.
<?php foreach($_SERVER as $key => $value): ?>
<?php foreach(array_filter($_SERVER) as $key => $value): ?>
<br /><?php print $key ?> : <?php print $value; ?>
<?php endforeach; ?>

Expand Down