|
1 | 1 | <?php
|
2 | 2 | namespace Codeception\Module;
|
3 | 3 |
|
| 4 | +use Codeception\Exception\ModuleConfigException; |
4 | 5 | use Codeception\Exception\ModuleException;
|
| 6 | +use Codeception\Lib\Connector\Guzzle6; |
5 | 7 | use Codeception\Lib\InnerBrowser;
|
6 | 8 | use Codeception\Lib\Interfaces\MultiSession;
|
7 | 9 | use Codeception\Lib\Interfaces\Remote;
|
|
29 | 31 | * ## Configuration
|
30 | 32 | *
|
31 | 33 | * * url *required* - start url of your app
|
| 34 | + * * handler (default: curl) - Guzzle handler to use. By default curl is used, also possible to pass `stream`, or any valid class name as [Handler](http://docs.guzzlephp.org/en/latest/handlers-and-middleware.html#handlers). |
| 35 | + * * middleware - Guzzle middlewares to add. An array of valid callables is required. |
32 | 36 | * * curl - curl options
|
33 | 37 | * * headers - ...
|
34 | 38 | * * cookies - ...
|
@@ -85,11 +89,13 @@ class PhpBrowser extends InnerBrowser implements Remote, MultiSession
|
85 | 89 | 'timeout' => 30,
|
86 | 90 | 'curl' => [],
|
87 | 91 | 'refresh_max_interval' => 10,
|
| 92 | + 'handler' => 'curl', |
| 93 | + 'middleware' => null, |
88 | 94 |
|
89 | 95 | // required defaults (not recommended to change)
|
90 | 96 | 'allow_redirects' => false,
|
91 | 97 | 'http_errors' => false,
|
92 |
| - 'cookies' => true |
| 98 | + 'cookies' => true, |
93 | 99 | ];
|
94 | 100 |
|
95 | 101 | protected $guzzleConfigFields = [
|
@@ -233,6 +239,13 @@ public function _initializeSession()
|
233 | 239 | if ($this->isGuzzlePsr7) {
|
234 | 240 | $defaults['base_uri'] = $this->config['url'];
|
235 | 241 | $defaults['curl'] = $curlOptions;
|
| 242 | + $handler = Guzzle6::createHandler($this->config['handler']); |
| 243 | + if ($handler && is_array($this->config['middleware'])) { |
| 244 | + foreach ($this->config['middleware'] as $middleware) { |
| 245 | + $handler->push($middleware); |
| 246 | + } |
| 247 | + } |
| 248 | + $defaults['handler'] = $handler; |
236 | 249 | $this->guzzle = new GuzzleClient($defaults);
|
237 | 250 | } else {
|
238 | 251 | $defaults['config']['curl'] = $curlOptions;
|
|
0 commit comments