amphp / http-server-static-content
Static content request handler for Amp's HTTP server.
Fund package maintenance!
amphp
Installs: 14 759
Dependents: 17
Suggesters: 0
Security: 0
Stars: 21
Watchers: 6
Forks: 12
Open Issues: 0
Requires
- php: >=8.1
- amphp/amp: ^3
- amphp/byte-stream: ^2
- amphp/cache: ^2
- amphp/file: ^3
- amphp/http: ^2-dev
- amphp/http-server: ^3
- amphp/pipeline: ^1
- revolt/event-loop: ^1 || ^0.2.4
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: 2023-05-23 03:21:45 UTC
README
This package provides a static content RequestHandler
implementations for the AMPHP HTTP server.
Usage
DocumentRoot
and StaticResource
implement RequestHandler
.
Example
<?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; $router->setFallback(new DocumentRoot(__DIR__ . '/public')); $router->addRoute('GET', '/', new ClosureRequestHandler(function () { return new Response(Status::OK, ['content-type' => 'text/plain'], 'Hello, world!'); })); $server->start($router, new DefaultErrorHandler());