Client.php 1.2 KB

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