9d64be7604fdcd88d4c0113c80ade0d9bd26c2a7
[yaffs-website] / vendor / behat / mink-goutte-driver / src / Goutte / Client.php
1 <?php
2
3 /*
4  * This file is part of the Behat\Mink.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Mink\Driver\Goutte;
12
13 use Goutte\Client as BaseClient;
14 use Symfony\Component\BrowserKit\Response;
15
16 /**
17  * Client overrides to support Mink functionality.
18  */
19 class Client extends BaseClient
20 {
21     /**
22      * Reads response meta tags to guess content-type charset.
23      *
24      * @param Response $response
25      *
26      * @return Response
27      */
28     protected function filterResponse($response)
29     {
30         $contentType = $response->getHeader('Content-Type');
31
32         if (!$contentType || false === strpos($contentType, 'charset=')) {
33             if (preg_match('/\<meta[^\>]+charset *= *["\']?([a-zA-Z\-0-9]+)/i', $response->getContent(), $matches)) {
34                 $headers = $response->getHeaders();
35                 $headers['Content-Type'] = $contentType.';charset='.$matches[1];
36
37                 $response = new Response($response->getContent(), $response->getStatus(), $headers);
38             }
39         }
40
41         return parent::filterResponse($response);
42     }
43 }