-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathsendfile_with_ssl.phpt
47 lines (45 loc) · 1.51 KB
/
sendfile_with_ssl.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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