mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-13 21:45:55 +00:00
wip
This commit is contained in:
@@ -75,8 +75,8 @@ class Factory
|
|||||||
|
|
||||||
protected function bindProxyManager()
|
protected function bindProxyManager()
|
||||||
{
|
{
|
||||||
app()->singleton(ProxyManager::class, function ($app) {
|
app()->bind(ProxyManager::class, function ($app) {
|
||||||
return new ProxyManager($app->make(Configuration::class), $this->loop, $app->make(HttpClient::class));
|
return new ProxyManager($app->make(Configuration::class), $this->loop);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,15 +49,9 @@ class HttpClient
|
|||||||
|
|
||||||
dump($this->request->getMethod() . ' ' . $this->request->getUri()->getPath());
|
dump($this->request->getMethod() . ' ' . $this->request->getUri()->getPath());
|
||||||
|
|
||||||
/**
|
transform($request, function ($request) use ($proxyConnection) {
|
||||||
* Modifiers can already send a response to the proxy connection,
|
$this->sendRequestToApplication($request, $proxyConnection);
|
||||||
* which would result in the request being null.
|
});
|
||||||
*/
|
|
||||||
if (is_null($request)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->sendRequestToApplication($request, $proxyConnection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function passRequestThroughModifiers(RequestInterface $request, ?WebSocket $proxyConnection = null): ?RequestInterface
|
protected function passRequestThroughModifiers(RequestInterface $request, ?WebSocket $proxyConnection = null): ?RequestInterface
|
||||||
@@ -103,7 +97,7 @@ class HttpClient
|
|||||||
/* @var $body \React\Stream\ReadableStreamInterface */
|
/* @var $body \React\Stream\ReadableStreamInterface */
|
||||||
$body = $response->getBody();
|
$body = $response->getBody();
|
||||||
|
|
||||||
$this->logResponse($response->buffer);
|
$this->logResponse(str($response));
|
||||||
|
|
||||||
$body->on('data', function ($chunk) use ($proxyConnection, $response) {
|
$body->on('data', function ($chunk) use ($proxyConnection, $response) {
|
||||||
$response->buffer .= $chunk;
|
$response->buffer .= $chunk;
|
||||||
@@ -127,12 +121,10 @@ class HttpClient
|
|||||||
|
|
||||||
protected function sendChunkToServer(string $chunk, ?WebSocket $proxyConnection = null)
|
protected function sendChunkToServer(string $chunk, ?WebSocket $proxyConnection = null)
|
||||||
{
|
{
|
||||||
if (is_null($proxyConnection)) {
|
transform($proxyConnection, function ($proxyConnection) use ($chunk) {
|
||||||
return;
|
$binaryMsg = new Frame($chunk, true, Frame::OP_BINARY);
|
||||||
}
|
$proxyConnection->send($binaryMsg);
|
||||||
|
});
|
||||||
$binaryMsg = new Frame($chunk, true, Frame::OP_BINARY);
|
|
||||||
$proxyConnection->send($binaryMsg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function logResponse(string $rawResponse)
|
protected function logResponse(string $rawResponse)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class CheckBasicAuthentication
|
|||||||
$this->configuration = $configuration;
|
$this->configuration = $configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(RequestInterface $request, WebSocket $proxyConnection): ?RequestInterface
|
public function handle(RequestInterface $request, ?WebSocket $proxyConnection): ?RequestInterface
|
||||||
{
|
{
|
||||||
if (! $this->requiresAuthentication() || is_null($proxyConnection)) {
|
if (! $this->requiresAuthentication() || is_null($proxyConnection)) {
|
||||||
return $request;
|
return $request;
|
||||||
|
|||||||
@@ -16,14 +16,10 @@ class ProxyManager
|
|||||||
/** @var LoopInterface */
|
/** @var LoopInterface */
|
||||||
protected $loop;
|
protected $loop;
|
||||||
|
|
||||||
/** @var HttpClient */
|
public function __construct(Configuration $configuration, LoopInterface $loop)
|
||||||
protected $httpClient;
|
|
||||||
|
|
||||||
public function __construct(Configuration $configuration, LoopInterface $loop, HttpClient $httpClient)
|
|
||||||
{
|
{
|
||||||
$this->configuration = $configuration;
|
$this->configuration = $configuration;
|
||||||
$this->loop = $loop;
|
$this->loop = $loop;
|
||||||
$this->httpClient = $httpClient;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createProxy(string $clientId, $connectionData)
|
public function createProxy(string $clientId, $connectionData)
|
||||||
@@ -48,6 +44,6 @@ class ProxyManager
|
|||||||
|
|
||||||
protected function performRequest(WebSocket $proxyConnection, $requestId, string $requestData)
|
protected function performRequest(WebSocket $proxyConnection, $requestId, string $requestData)
|
||||||
{
|
{
|
||||||
$this->httpClient->performRequest((string)$requestData, $proxyConnection, $requestId);
|
app(HttpClient::class)->performRequest((string)$requestData, $proxyConnection, $requestId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ abstract class PostController extends Controller
|
|||||||
|
|
||||||
public function onOpen(ConnectionInterface $connection, RequestInterface $request = null)
|
public function onOpen(ConnectionInterface $connection, RequestInterface $request = null)
|
||||||
{
|
{
|
||||||
dump(memory_get_usage(true));
|
|
||||||
$connection->contentLength = $this->findContentLength($request->getHeaders());
|
$connection->contentLength = $this->findContentLength($request->getHeaders());
|
||||||
|
|
||||||
$connection->requestBuffer = (string) $request->getBody();
|
$connection->requestBuffer = (string) $request->getBody();
|
||||||
|
|||||||
Reference in New Issue
Block a user