2017-05-21 21:16:32 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace JKingWeb\Arsse;
|
2017-08-29 14:50:31 +00:00
|
|
|
|
2017-10-01 13:33:49 +00:00
|
|
|
require_once __DIR__."/bootstrap.php";
|
2017-05-21 21:16:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
This is a so-called router for the the internal PHP Web server:
|
|
|
|
<http://php.net/manual/en/features.commandline.webserver.php>
|
|
|
|
|
2017-08-29 15:16:37 +00:00
|
|
|
It is used to test feed parsing in a controlled environment,
|
2017-05-21 21:16:32 +00:00
|
|
|
answering specific requests used in tests with the data required
|
2017-08-29 15:16:37 +00:00
|
|
|
to pass the test.
|
2017-05-21 21:16:32 +00:00
|
|
|
|
2017-08-29 15:16:37 +00:00
|
|
|
The parameters of the responses are kept in separate files,
|
2017-05-21 21:16:32 +00:00
|
|
|
which include the following data:
|
|
|
|
|
|
|
|
- Response content
|
|
|
|
- Response code
|
|
|
|
- Content type
|
|
|
|
- Whether to send cache headers
|
|
|
|
- Last modified
|
|
|
|
- Any other headers
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2017-05-27 22:15:52 +00:00
|
|
|
ignore_user_abort(false);
|
2017-05-21 21:16:32 +00:00
|
|
|
$defaults = [ // default values for response
|
|
|
|
'code' => 200,
|
|
|
|
'content' => "",
|
|
|
|
'mime' => "application/octet-stream",
|
|
|
|
'lastMod' => time(),
|
|
|
|
'cache' => true,
|
|
|
|
'fields' => [],
|
|
|
|
];
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
$url = explode("?", $_SERVER['REQUEST_URI'])[0];
|
2017-05-21 21:16:32 +00:00
|
|
|
$base = BASE."tests".\DIRECTORY_SEPARATOR."docroot";
|
2017-08-29 14:50:31 +00:00
|
|
|
$test = $base.str_replace("/", \DIRECTORY_SEPARATOR, $url).".php";
|
|
|
|
if (!file_exists($test)) {
|
2017-05-21 21:16:32 +00:00
|
|
|
$response = [
|
|
|
|
'code' => 499,
|
|
|
|
'content' => "Test '$test' missing.",
|
|
|
|
'mime' => "application/octet-stream",
|
|
|
|
'lastMod' => time(),
|
|
|
|
'cache' => true,
|
|
|
|
'fields' => [],
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
$response = array_merge($defaults, (include $test));
|
|
|
|
}
|
|
|
|
// set the response code
|
|
|
|
http_response_code((int) $response['code']);
|
|
|
|
// if the response has a body, set the content type and (possibly) the ETag.
|
2017-08-29 14:50:31 +00:00
|
|
|
if (strlen($response['content'])) {
|
2017-05-21 21:16:32 +00:00
|
|
|
header("Content-Type: ".$response['mime']);
|
2017-08-29 14:50:31 +00:00
|
|
|
if ($response['cache']) {
|
|
|
|
header('ETag: "'.md5($response['content']).'"');
|
|
|
|
}
|
2017-05-21 21:16:32 +00:00
|
|
|
}
|
|
|
|
// if caching is enabled, set the last-modified date
|
2017-08-29 14:50:31 +00:00
|
|
|
if ($response['cache']) {
|
|
|
|
header("Last-Modified: ".gmdate("D, d M Y H:i:s \G\M\T", $response['lastMod']));
|
|
|
|
}
|
2017-05-21 21:16:32 +00:00
|
|
|
// set any other specified fields verbatim
|
2017-08-29 14:50:31 +00:00
|
|
|
foreach ($response['fields'] as $h) {
|
2017-05-21 21:16:32 +00:00
|
|
|
header($h);
|
|
|
|
}
|
|
|
|
// send the content
|
2017-08-29 14:50:31 +00:00
|
|
|
echo $response['content'];
|