function DrupalTestBrowser::filterResponse

Reads response meta tags to guess content-type charset.

Parameters

\Symfony\Component\BrowserKit\Response $response: The origin response to filter.

Return value

\Symfony\Component\BrowserKit\Response A BrowserKit Response instance.

File

core/tests/Drupal/Tests/DrupalTestBrowser.php, line 251

Class

DrupalTestBrowser
Enables a BrowserKitDriver mink driver to use a Guzzle client.

Namespace

Drupal\Tests

Code

protected function filterResponse($response) {
    $content_type = $response->getHeader('Content-Type');
    if (!$content_type || strpos($content_type, 'charset=') === FALSE) {
        if (preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9]+)/i', $response->getContent(), $matches)) {
            $headers = $response->getHeaders();
            $headers['Content-Type'] = $content_type . ';charset=' . $matches[1];
            $response = new Response($response->getContent(), $response->getStatus(), $headers);
        }
    }
    return parent::filterResponse($response);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.