diff --git a/src/Network/Http/Adapter/Stream.php b/src/Network/Http/Adapter/Stream.php index 378a4bf6317..f0480c8254e 100644 --- a/src/Network/Http/Adapter/Stream.php +++ b/src/Network/Http/Adapter/Stream.php @@ -35,12 +35,19 @@ class Stream protected $_context; /** - * Array of options/content for the stream context. + * Array of options/content for the http stream context. * * @var array */ protected $_contextOptions; + /** + * Array of options/content for the ssl stream context. + * + * @var array + */ + protected $_sslContextOptions; + /** * The stream resource. * @@ -67,6 +74,7 @@ public function send(Request $request, array $options) $this->_stream = null; $this->_context = []; $this->_contextOptions = []; + $this->_sslContextOptions = []; $this->_connectionErrors = []; $this->_buildContext($request, $options); @@ -119,9 +127,7 @@ protected function _buildContext(Request $request, $options) if ($scheme === 'https') { $this->_buildSslContext($request, $options); } - $this->_context = stream_context_create([ - 'http' => $this->_contextOptions - ]); + $this->_context = stream_context_create($this->contextOptions()); } /** @@ -225,12 +231,12 @@ protected function _buildSslContext(Request $request, $options) if (!empty($options['ssl_verify_host'])) { $url = $request->url(); $host = parse_url($url, PHP_URL_HOST); - $this->_contextOptions['CN_match'] = $host; + $this->_sslContextOptions['CN_match'] = $host; } foreach ($sslOptions as $key) { if (isset($options[$key])) { $name = substr($key, 4); - $this->_contextOptions[$name] = $options[$key]; + $this->_sslContextOptions[$name] = $options[$key]; } } } @@ -303,6 +309,9 @@ protected function _connectionErrorHandler($code, $message) */ public function contextOptions() { - return $this->_contextOptions; + return [ + 'http' => $this->_contextOptions, + 'ssl' => $this->_sslContextOptions, + ]; } } diff --git a/tests/TestCase/Network/Http/Adapter/StreamTest.php b/tests/TestCase/Network/Http/Adapter/StreamTest.php index 5d95109921d..5ac4edfe4ee 100644 --- a/tests/TestCase/Network/Http/Adapter/StreamTest.php +++ b/tests/TestCase/Network/Http/Adapter/StreamTest.php @@ -84,9 +84,9 @@ public function testBuildingContextHeader() 'Content-Type: application/json', 'Cookie: testing=value; utm_src=awesome', ]; - $this->assertEquals(implode("\r\n", $expected), $result['header']); - $this->assertEquals($options['redirect'], $result['max_redirects']); - $this->assertTrue($result['ignore_errors']); + $this->assertEquals(implode("\r\n", $expected), $result['http']['header']); + $this->assertEquals($options['redirect'], $result['http']['max_redirects']); + $this->assertTrue($result['http']['ignore_errors']); } /** @@ -114,8 +114,8 @@ public function testSendContextContentString() 'User-Agent: CakePHP', 'Content-Type: application/json', ]; - $this->assertEquals(implode("\r\n", $expected), $result['header']); - $this->assertEquals($content, $result['content']); + $this->assertEquals(implode("\r\n", $expected), $result['http']['header']); + $this->assertEquals($content, $result['http']['content']); } /** @@ -139,9 +139,9 @@ public function testSendContextContentArray() 'User-Agent: CakePHP', 'Content-Type: multipart/form-data; boundary="', ]; - $this->assertStringStartsWith(implode("\r\n", $expected), $result['header']); - $this->assertContains('Content-Disposition: form-data; name="a"', $result['content']); - $this->assertContains('my value', $result['content']); + $this->assertStringStartsWith(implode("\r\n", $expected), $result['http']['header']); + $this->assertContains('Content-Disposition: form-data; name="a"', $result['http']['content']); + $this->assertContains('my value', $result['http']['content']); } /** @@ -169,7 +169,7 @@ public function testSendContextSsl() 'allow_self_signed' => false, ]; foreach ($expected as $k => $v) { - $this->assertEquals($v, $result[$k]); + $this->assertEquals($v, $result['ssl'][$k]); } }