add bytes returned macos support, update realpath dump, change response condition

This commit is contained in:
yggverse 2024-04-28 17:22:16 +03:00
parent 8745b4aa00
commit 9c0bfd3e58
2 changed files with 8 additions and 5 deletions

View File

@ -36,13 +36,14 @@ php src/nex.php host=127.0.0.1 port=1900 path=/target/dir
* `list` - show content listing in the requested directory (when index file not found), `yes` by default * `list` - show content listing in the requested directory (when index file not found), `yes` by default
* `fail` - **filepath** that contain failure text or template (e.g. `error.gmi`), `fail` text by default * `fail` - **filepath** that contain failure text or template (e.g. `error.gmi`), `fail` text by default
* `size` - limit request length in bytes, `1024` by default * `size` - limit request length in bytes, `1024` by default
* `dump` - dump queries or set blank to disable, default: `[{time}] [{code}] {host}:{port} {path} {real}` * `dump` - dump queries or blank to disable, default: `[{time}] [{code}] {host}:{port} {path} {real} {size} bytes`
* `{time}` - event time in `c` format * `{time}` - event time in `c` format
* `{code}` - formal response code: `1` - found, `0` - not found * `{code}` - formal response code: `1` - found, `0` - not found
* `{host}` - peer host * `{host}` - peer host
* `{port}` - peer port * `{port}` - peer port
* `{path}` - path requested * `{path}` - path requested
* `{real}` - **realpath** returned * `{real}` - **realpath** returned
* `{size}` - response size in bytes
### Autostart ### Autostart

View File

@ -167,7 +167,7 @@ if (!defined('NEXT_SIZE')) define('NEXT_SIZE', 1024);
if (!defined('NEXT_FAIL')) define('NEXT_FAIL', 'fail'); if (!defined('NEXT_FAIL')) define('NEXT_FAIL', 'fail');
if (!defined('NEXT_DUMP')) define('NEXT_DUMP', '[{time}] [{code}] {host}:{port} {path} {real}'); if (!defined('NEXT_DUMP')) define('NEXT_DUMP', '[{time}] [{code}] {host}:{port} {path} {real} {size} bytes');
// Init server // Init server
$server = new \Yggverse\Nex\Server( $server = new \Yggverse\Nex\Server(
@ -331,14 +331,16 @@ $server->start(
'{port}', '{port}',
'{path}', '{path}',
'{real}', '{real}',
'{size}'
], ],
[ [
(string) date('c'), (string) date('c'),
(string) (int) !empty($response), (string) (int) !empty($response),
(string) parse_url($url, PHP_URL_HOST), (string) parse_url($url, PHP_URL_HOST),
(string) parse_url($url, PHP_URL_PORT), (string) parse_url($url, PHP_URL_PORT),
(string) str_replace('%', '%%', empty($request) ? '/' : $request), (string) str_replace('%', '%%', empty($request) ? '/' : $request),
(string) str_replace('%', '%%', $realpath) (string) str_replace('%', '%%', empty($realpath) ? '!' : $realpath),
(string) mb_strlen((string) $response)
], ],
NEXT_DUMP NEXT_DUMP
) . PHP_EOL ) . PHP_EOL
@ -346,6 +348,6 @@ $server->start(
} }
// Send response // Send response
return is_null($response) ? NEXT_FAIL : $response; return is_string($response) ? $response : NEXT_FAIL;
} }
); );