amphp / http-server-static-content
Amp HTTP服务器静态内容请求处理器。
v2.0.0
2023-08-20 14:58 UTC
Requires
- php: >=8.1
- amphp/amp: ^3
- amphp/byte-stream: ^2
- amphp/cache: ^2
- amphp/file: ^3
- amphp/http: ^2
- amphp/http-server: ^3
- amphp/pipeline: ^1
- revolt/event-loop: ^1
Requires (Dev)
- amphp/http-server-router: ^2
- amphp/log: ^2
- amphp/php-cs-fixer-config: ^2
- amphp/phpunit-util: ^3
- danielmiessler/sec-lists: 2022.4
- phpunit/phpunit: ^9
- psalm/phar: ^5.6
This package is auto-updated.
Last update: 2024-08-23 09:42:36 UTC
README
AMPHP 是一套为 PHP 设计的事件驱动库集合,考虑到纤维和并发。本包提供了一个 HTTP 服务器 插件,可以轻松地提供静态文件,如 HTML、CSS、JavaScript 和图片。
安装
本包可以作为 Composer 依赖项安装。
composer require amphp/http-server-static-content
用法
本包提供了两个 RequestHandler
实现
DocumentRoot
: 在一个目录内提供所有文件。StaticResource
: 提供单个特定的文件。
以下示例结合了静态文件服务和 请求路由,以演示它们如何很好地协同工作。
<?php use Amp\Http\Server\DefaultErrorHandler; use Amp\Http\Server\RequestHandler\ClosureRequestHandler; use Amp\Http\Server\Response; use Amp\Http\Server\SocketHttpServer; use Amp\Http\Server\StaticContent\DocumentRoot; use Amp\Http\Status; $router = new Amp\Http\Server\Router; // $server is an instance of HttpServer and $errorHandler an instance of ErrorHandler $router->setFallback(new DocumentRoot($server, $errorHandler, __DIR__ . '/public')); $router->addRoute('GET', '/', new ClosureRequestHandler(function () { return new Response(Status::OK, ['content-type' => 'text/plain'], 'Hello, world!'); })); $server->start($router, new DefaultErrorHandler());
完整示例请参阅 examples/server.php
。
贡献
请阅读 我们的规则 了解我们的行为准则以及向我们提交拉取请求的过程。
安全性
如果您发现任何安全相关的问题,请使用私有安全问题报告器而不是公共问题跟踪器。
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 LICENSE。