pedrogaldino / php-proxy-server
Servidor de proxy com suporte a HTTP(S) implementado em PHP
v1.0-beta.15
2020-11-09 17:52 UTC
Requires
- php: >=7.0
- ext-json: *
- clue/http-proxy-react: ^1.5
- guzzlehttp/guzzle: ~6.0
- react/event-loop: ^1.1.1
- react/http: ^1.1
- tightenco/collect: ^7.3
Requires (Dev)
- seregazhuk/php-watcher: ^0.5.2
This package is auto-updated.
Last update: 2024-10-19 23:20:40 UTC
README
Proxy server with HTTP(S) support implemented in PHP.
Instalation
Package Installation:
composer require pedrogaldino/php-proxy-server
Quick Start
First, start the service as follows:
<?php
namespace App\Services\Proxy;
use Galdino\Proxy\Server\Request;
use Galdino\Proxy\Server\Response;
use Galdino\Proxy\Server\Contracts\RequestInterceptorContract;
use Galdino\Proxy\Server\ProxyMiddleware;
use Galdino\Proxy\Server\ProxyServer;
class MyProxyServer extends ProxyMiddleware implements RequestInterceptorContract
{
protected $proxy;
public function __construct()
{
$this->proxy = new ProxyServer($this);
}
...
Then implement the middleware events:
...
public function onReceiveRequest(Request $request): Promise
{
return new Promise(function ($resolve, $reject) use($request) {
print 'Before client request' . PHP_EOL;
//...
$resolve($request);
});
}
public function afterRetryProxyRequest(Request $request, Response $response) : Promise
{
return new \React\Promise\Promise(function($resolve, $reject) use($request, $response) {
print 'After proxy request' . PHP_EOL;
//...
$resolve([$request, $response]);
});
}
public function beforeClientResponse(Request $request, Response $response): Promise
{
return new \React\Promise\Promise(function($resolve, $reject) use($request, $response) {
print 'Before client response' . PHP_EOL;
//...
$resolve([$request, $response]);
});
}
public function onError($exception, Request $request = null, Response $response = null): Promise
{
return new \React\Promise\Promise(function($resolve, $reject) use($exception, $request, $response) {
print 'On error' . PHP_EOL;
$resolve([$exception, $request, $response]);
});
}
...