Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not send headers by SAPI #3571

Merged
merged 4 commits into from
Aug 19, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests
sshymko authored and twose committed Aug 15, 2020
commit 2948e27906d1e1ec44492e02c153946d87088d52
49 changes: 49 additions & 0 deletions tests/swoole_http_server/headers_sent.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
--TEST--
swoole_http_server: headers sent (coroutine disabled)
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';

$pm = new ProcessManager;

$pm->parentFunc = function () use ($pm) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://127.0.0.1:{$pm->getFreePort()}/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
echo curl_exec($ch);
echo curl_exec($ch);
curl_close($ch);
$pm->kill();
};

$pm->childFunc = function () use ($pm) {
$http = new swoole_http_server('127.0.0.1', $pm->getFreePort());
$http->set([
'worker_num' => 1,
'enable_coroutine' => false,
'log_file' => '/dev/null'
]);
$http->on('workerStart', function () use ($pm) {
$pm->wakeup();
});
$http->on('request', function (swoole_http_request $request, swoole_http_response $response) {
ob_start();
echo 'Test';
$output = ob_get_clean();
$response->write('buffered_output=' . $output . "\n");
$response->write('headers_sent=' . (int)headers_sent() . "\n");
$response->end();
});
$http->start();
};

$pm->childFirst();
$pm->run();
?>
--EXPECT--
buffered_output=Test
headers_sent=0
buffered_output=Test
headers_sent=0
48 changes: 48 additions & 0 deletions tests/swoole_http_server/output_buffering.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
--TEST--
swoole_http_server: output buffering
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';

$pm = new ProcessManager;

$pm->parentFunc = function () use ($pm) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://127.0.0.1:{$pm->getFreePort()}/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
echo curl_exec($ch);
echo curl_exec($ch);
curl_close($ch);
$pm->kill();
};

$pm->childFunc = function () use ($pm) {
$http = new swoole_http_server('127.0.0.1', $pm->getFreePort());
$http->set([
'worker_num' => 1,
'log_file' => '/dev/null'
]);
$http->on('workerStart', function () use ($pm) {
$pm->wakeup();
});
$http->on('request', function (swoole_http_request $request, swoole_http_response $response) {
ob_start();
echo 'Test';
$output = ob_get_clean();
$response->write('buffered_output=' . $output . "\n");
$response->write('headers_sent=' . (int)headers_sent() . "\n");
$response->end();
});
$http->start();
};

$pm->childFirst();
$pm->run();
?>
--EXPECT--
buffered_output=Test
headers_sent=0
buffered_output=Test
headers_sent=0