Skip to content

Commit 36a1dc2

Browse files
authored
Fix issue 3988 (swoole#3990)
* Fix issue 3988 * Add test * Don't create socket in enableSSL * Fix test * Enable ssl in PHP_METHOD(swoole_client_coro, enableSSL) * Enable ssl before php_swoole_socket_set_ssl
1 parent 1f3000b commit 36a1dc2

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

ext-src/swoole_client_coro.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,9 +867,11 @@ static PHP_METHOD(swoole_client_coro, close) {
867867
#ifdef SW_USE_OPENSSL
868868
static PHP_METHOD(swoole_client_coro, enableSSL) {
869869
Socket *cli = client_get_ptr(ZEND_THIS);
870+
870871
if (!cli) {
871872
RETURN_FALSE;
872873
}
874+
873875
if (cli->get_type() != SW_SOCK_TCP && cli->get_type() != SW_SOCK_TCP6) {
874876
php_swoole_fatal_error(E_WARNING, "cannot use enableSSL");
875877
RETURN_FALSE;
@@ -878,6 +880,9 @@ static PHP_METHOD(swoole_client_coro, enableSSL) {
878880
php_swoole_fatal_error(E_WARNING, "SSL has been enabled");
879881
RETURN_FALSE;
880882
}
883+
884+
cli->enable_ssl_encrypt();
885+
881886
zval *zset = sw_zend_read_property_ex(swoole_client_coro_ce, ZEND_THIS, SW_ZSTR_KNOWN(SW_ZEND_STR_SETTING), 0);
882887
if (php_swoole_array_length_safe(zset) > 0) {
883888
php_swoole_socket_set_ssl(cli, zset);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
swoole_client_coro: enableSSL
3+
--SKIPIF--
4+
<?php require __DIR__ . '/../include/skipif.inc'; ?>
5+
--FILE--
6+
<?php
7+
require __DIR__ . '/../include/bootstrap.php';
8+
9+
use Swoole\Coroutine\Client;
10+
11+
use function Swoole\Coroutine\run;
12+
13+
run(function () {
14+
$client = new Client(SWOOLE_SOCK_TCP);
15+
$client->connect('www.baidu.com', 443);
16+
$client->enableSSL();
17+
18+
$http = "GET / HTTP/1.0\r\nAccept: */*User-Agent: Lowell-Agent\r\nHost: www.baidu.com\r\nConnection: Close\r\n\r\n";
19+
if (!$client->send($http)) {
20+
echo "ERROR\n";
21+
}
22+
23+
$content = '';
24+
while (true) {
25+
$read = $client->recv();
26+
if (empty($read)) {
27+
break;
28+
}
29+
$content .= $read;
30+
}
31+
$client->close();
32+
Assert::assert(strpos($content, 'map.baidu.com') !== false);
33+
});
34+
?>
35+
--EXPECT--

0 commit comments

Comments
 (0)