rauny-henrique / php-proxy-server
Servidor de proxy com suporte a HTTP(S) implementado em PHP
v1.0-beta.6
2020-06-26 21:53 UTC
Requires
- ext-json: *
- clue/buzz-react: ^2.8
- clue/http-proxy-react: ^1.4
- guzzlehttp/guzzle: ~6.0
- react/event-loop: ^1.1
- react/http: ^0.8.6
- react/http-client: ^0.5.10
- tightenco/collect: ^7.3
Requires (Dev)
- seregazhuk/php-watcher: ^0.5.2
This package is auto-updated.
Last update: 2024-11-11 04:08:50 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]);
});
}
...