phprivoxy/application

使用PSR15中间件作为流量处理器的代理服务器应用程序创建框架。

This package is auto-updated.

Last update: 2024-09-02 13:08:49 UTC


README

使用PSR15中间件作为流量处理器的代理服务器应用程序创建框架。

此代理服务器应用程序框架基于Workerman框架(https://github.com/walkor/workerman)。

使用此框架,创建代理服务器时,将进入适当的PSR15中间件开发,具有必要的功能。

要求

  • PHP >= 8.1

安装

使用composer(推荐)

composer create phprivoxy/application

简单的SSL MITM(中间人)代理示例

use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;

class DummyMiddleware implements MiddlewareInterface
{
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        return $handler->handle($request);
    }
}

class HttpClientMiddleware implements MiddlewareInterface
{
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $client = new GuzzleHttp\Client();
        try {
            $response = $client->send($request, ['allow_redirects' => false]);
        } catch (GuzzleHttp\Exception\ConnectException $e) {
            // Do something
        } catch (GuzzleHttp\Exception\BadResponseException $e) {
            return $e->getResponse();
        }

        return $response;
    }
}

$processes = 4; // Default 1.

$app = new PHPrivoxy\Application\Application($processes);
$app->add(new DummyMiddleware());
$app->add(new HttpClientMiddleware()); // HttpClient must be last in queue (it generate response).
$app->run(); // By default, it listen all connections on 8080 port.

此示例您也可以在 "tests" 目录中找到。

只需运行它

php tests/test.php start

首次运行时,此应用程序将在CA子目录中创建一个自签名的SSL根证书。请在您的浏览器中将此自签名的CA证书添加到受信任的证书中!

对于每个网站,应用程序将在 "certificates" 子目录中生成一个自签名的证书。

在此示例中,我们使用简单的PSR-15兼容的HttpClientMiddleware进行站点下载。您也可以根据您的目标和需求在队列中添加自己的PSR-15兼容中间件。

许可证

MIT许可证 查看 LICENSE