Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added fix for supporting content-type meta tags

  • Loading branch information...
commit c40d4bd483ccaf7caebd2796922636129682f4b1 1 parent a32b9ff
@everzet everzet authored
View
40 src/Behat/Mink/Driver/Goutte/Client.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace Behat\Mink\Driver\Goutte;
+
+use Goutte\Client as BaseClient;
+use Guzzle\Message\Response as GuzzleResponse;
+
+/*
+ * This file is part of the Behat\Mink.
+ * (c) Konstantin Kudryashov <ever.zet@gmail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Client overrides to support Mink functionality.
+ */
+class Client extends BaseClient
+{
+ /**
+ * Reads response meta tags to guess content-type charset.
+ */
+ protected function createResponse(GuzzleResponse $response)
+ {
+ $body = $response->getBody(true);
+ $statusCode = $response->getStatusCode();
+ $headers = $response->getHeaders()->getAll();
+ $contentType = $response->getContentType();
+
+ if (!$contentType || false === strpos($contentType, 'charset=')) {
+ if (preg_match('/\<meta[^\>]+charset *= *["\']?([a-zA-Z\-0-9]+)/', $body, $matches)) {
+ $contentType .= ';charset='.$matches[1];
+ }
+ }
+ $headers['Content-Type'] = $contentType;
+
+ return new Response($body, $statusCode, $headers);
+ }
+}
View
2  src/Behat/Mink/Driver/GoutteDriver.php
@@ -9,7 +9,7 @@
Symfony\Component\DomCrawler\Field,
Symfony\Component\DomCrawler\Field\FormField;
-use Goutte\Client as GoutteClient,
+use Behat\Mink\Driver\Goutte\Client as GoutteClient,
Behat\Mink\Session,
Behat\Mink\Element\NodeElement,
Behat\Mink\Exception\DriverException,
View
2  src/Behat/Mink/PHPUnit/TestCase.php
@@ -2,7 +2,7 @@
namespace Behat\Mink\PHPUnit;
-use Goutte\Client as GoutteClient,
+use Behat\Mink\Driver\Goutte\Client as GoutteClient,
Behat\Mink\Mink,
Behat\Mink\Session,
Behat\Mink\Driver\GoutteDriver,
Please sign in to comment.
Something went wrong with that request. Please try again.