中间件 / proxy
用于转发请求并返回响应的中间件
v2.0.0
2020-12-03 23:38 UTC
Requires
- php: ^7.2 || ^8.0
- guzzlehttp/guzzle: ^6.2
- psr/http-server-middleware: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0
- laminas/laminas-diactoros: ^2.3
- middlewares/utils: ^3.0
- oscarotero/php-cs-fixer-config: ^1.0
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^8|^9
- squizlabs/php_codesniffer: ^3.0
README
使用Guzzle创建http代理的中间件。
要求
- PHP >= 7.2
- PSR-7 http库
- PSR-15中间件分发器
安装
此包可通过Composer安装和自动加载,名称为middlewares/proxy。
composer require middlewares/proxy
示例
$target = new Uri('http://api.example.com'); $dispatcher = new Dispatcher([ new Middlewares\Proxy($target) ]); $response = $dispatcher->dispatch(new ServerRequest());
用法
您需要一个具有代理目标的Psr\Http\Message\UriInterface
。
use Middlewares\Utils\Dispatcher; use Middlewares\Utils\Factory; $target = Factory::createUri('http://api.example.com'); Dispatcher::run([ new Middlewares\Proxy($target) ]);
client
用于执行请求的客户端实例。如果没有提供,将自动创建一个GuzzleHttp\Client
实例。
$target = Factory::createUri('http://api.example.com'); $client = new Client(); $proxy = (new Middlewares\Proxy($target))->client($client);
options
传递给guzzle客户端的选项。有关更多信息,请参阅guzzle文档
有关最近更改的更多信息,请参阅CHANGELOG,有关贡献详情,请参阅CONTRIBUTING。
MIT许可(MIT)。有关更多信息,请参阅LICENSE。