-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* improve httpclient * fix bugs * improve library, fix type * fix tests
- Loading branch information
Showing
9 changed files
with
204 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--TEST-- | ||
swoole_http_server: sendfile with dispatch_mode=7 | ||
--SKIPIF-- | ||
<?php require __DIR__ . '/../include/skipif.inc'; ?> | ||
--FILE-- | ||
<?php | ||
require __DIR__ . '/../include/bootstrap.php'; | ||
|
||
use Swoole\Coroutine\Http\Client; | ||
use Swoole\WebSocket\Server; | ||
|
||
use function Swoole\Coroutine\run; | ||
use function Swoole\Coroutine\go; | ||
|
||
$pm = new ProcessManager; | ||
|
||
$pm->parentFunc = function ($pid) use ($pm) { | ||
run(function () use ($pm) { | ||
$n = MAX_CONCURRENCY_LOW; | ||
while ($n--) { | ||
go(function () use ($pm) { | ||
$cli = new Client('127.0.0.1', $pm->getFreePort()); | ||
$cli->setHeaders(['KeepAlive' => 'off', 'Connection' => 'close']); | ||
for ($i = MAX_REQUESTS_LOW; $i--;) { | ||
$cli->get('/'); | ||
Assert::contains($cli->getBody(), 'swoole_http_server: sendfile with dispatch_mode=7'); | ||
} | ||
}); | ||
} | ||
}); | ||
echo "DONE\n"; | ||
$pm->kill(); | ||
}; | ||
|
||
$pm->childFunc = function () use ($pm) { | ||
$http = new Server('0.0.0.0', $pm->getFreePort(), SWOOLE_PROCESS, SWOOLE_SOCK_TCP); | ||
$http->set([ | ||
'log_file' => '/dev/null', | ||
'dispatch_mode' => 7, | ||
]); | ||
$http->on('workerStart', function () use ($pm) { | ||
$pm->wakeup(); | ||
}); | ||
$http->on('request', function (swoole_http_request $request, swoole_http_response $response) { | ||
$response->sendfile(__FILE__); | ||
}); | ||
|
||
$http->on('message', function(){}); | ||
$http->start(); | ||
}; | ||
$pm->childFirst(); | ||
$pm->run(); | ||
?> | ||
--EXPECT-- | ||
DONE |
54 changes: 54 additions & 0 deletions
54
tests/swoole_http_server/sendfile_with_dispatch_mode_7.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--TEST-- | ||
swoole_http_server: sendfile with dispatch_mode=7 | ||
--SKIPIF-- | ||
<?php require __DIR__ . '/../include/skipif.inc'; ?> | ||
--FILE-- | ||
<?php | ||
require __DIR__ . '/../include/bootstrap.php'; | ||
|
||
use Swoole\Coroutine\Http\Client; | ||
use Swoole\WebSocket\Server; | ||
|
||
use function Swoole\Coroutine\run; | ||
use function Swoole\Coroutine\go; | ||
|
||
$pm = new ProcessManager; | ||
|
||
$pm->parentFunc = function ($pid) use ($pm) { | ||
run(function () use ($pm) { | ||
$n = MAX_CONCURRENCY_LOW; | ||
while ($n--) { | ||
go(function () use ($pm) { | ||
$cli = new Client('127.0.0.1', $pm->getFreePort()); | ||
for ($i = MAX_REQUESTS_LOW; $i--;) { | ||
$cli->get('/'); | ||
Assert::contains($cli->getBody(), 'swoole_http_server: sendfile with dispatch_mode=7'); | ||
} | ||
}); | ||
} | ||
}); | ||
echo "DONE\n"; | ||
$pm->kill(); | ||
}; | ||
|
||
$pm->childFunc = function () use ($pm) { | ||
$http = new Server('0.0.0.0', $pm->getFreePort(), SWOOLE_PROCESS, SWOOLE_SOCK_TCP); | ||
$http->set([ | ||
'log_file' => '/dev/null', | ||
'dispatch_mode' => 7, | ||
]); | ||
$http->on('workerStart', function () use ($pm) { | ||
$pm->wakeup(); | ||
}); | ||
$http->on('request', function (swoole_http_request $request, swoole_http_response $response) { | ||
$response->sendfile(__FILE__); | ||
}); | ||
|
||
$http->on('message', function(){}); | ||
$http->start(); | ||
}; | ||
$pm->childFirst(); | ||
$pm->run(); | ||
?> | ||
--EXPECT-- | ||
DONE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--TEST-- | ||
swoole_http_server: sendfile with ssl | ||
--SKIPIF-- | ||
<?php require __DIR__ . '/../include/skipif.inc'; ?> | ||
--FILE-- | ||
<?php | ||
require __DIR__ . '/../include/bootstrap.php'; | ||
|
||
$pm = new ProcessManager; | ||
$pm->parentFunc = function ($pid) use ($pm) { | ||
for ($i = MAX_REQUESTS; $i--;) { | ||
$send_file = get_safe_random(mt_rand(0, 65535 * 10)); | ||
file_put_contents('/tmp/sendfile.txt', $send_file); | ||
|
||
$ctxArr = [ | ||
'verify_peer' => false, | ||
]; | ||
$ctx = stream_context_create(['ssl' => $ctxArr]); | ||
$recv_file = file_get_contents("https://127.0.0.1:{$pm->getFreePort()}", false, $ctx); | ||
Assert::same($send_file, $recv_file); | ||
} | ||
echo "DONE\n"; | ||
$pm->kill(); | ||
}; | ||
$pm->childFunc = function () use ($pm) { | ||
$http = new swoole_http_server('127.0.0.1', $pm->getFreePort(), SERVER_MODE_RANDOM, SWOOLE_SOCK_TCP | SWOOLE_SSL); | ||
$http->set([ | ||
'worker_num' => 1, | ||
'log_file' => '/dev/null', | ||
'ssl_cert_file' => SSL_FILE_DIR . '/server.crt', | ||
'ssl_key_file' => SSL_FILE_DIR . '/server.key', | ||
]); | ||
$http->on('workerStart', function () use ($pm) { | ||
$pm->wakeup(); | ||
}); | ||
$http->on('request', function (swoole_http_request $request, swoole_http_response $response) { | ||
$response->header('Content-Type', 'application/octet-stream'); | ||
$response->header('Content-Disposition', 'attachment; filename=recvfile.txt'); | ||
$response->sendfile('/tmp/sendfile.txt'); | ||
}); | ||
$http->start(); | ||
}; | ||
$pm->childFirst(); | ||
$pm->run(); | ||
?> | ||
--EXPECT-- | ||
DONE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters