5 Commits

Author SHA1 Message Date
René Preuß
763b45a77e Remove rewrite header 2021-01-01 20:13:08 +01:00
René Preuß
f137ea298b Fix prepare method to generate a valid dsn 2021-01-01 20:07:18 +01:00
René Preuß
2f457352c5 Undo test rename 2021-01-01 17:28:10 +01:00
René Preuß
c5cdd8c352 Fix style ci 2021-01-01 16:55:52 +01:00
René Preuß
6f72d719bf Fix http/s protocol headers
Improve request ids
2021-01-01 16:06:59 +01:00
4 changed files with 25 additions and 41 deletions

View File

@@ -60,16 +60,11 @@ class Client
return $sharedUrl;
}
$url = Arr::get($parsedUrl, 'host', Arr::get($parsedUrl, 'path'));
$host = Arr::get($parsedUrl, 'host', Arr::get($parsedUrl, 'path', 'localhost'));
$scheme = Arr::get($parsedUrl, 'scheme', 'http');
$port = Arr::get($parsedUrl, 'port', $scheme === 'https' ? 443 : 80);
if (Arr::get($parsedUrl, 'scheme') === 'https') {
$url .= ':443';
}
if (! is_null($port = Arr::get($parsedUrl, 'port'))) {
$url .= ":{$port}";
}
return $url;
return sprintf('%s://%s:%s', $scheme, $host, $port);
}
public function connectToServer(string $sharedUrl, $subdomain, $authToken = ''): PromiseInterface

View File

@@ -11,10 +11,12 @@ use function GuzzleHttp\Psr7\str;
use Laminas\Http\Request;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;
use Ratchet\Client\WebSocket;
use Ratchet\RFC6455\Messaging\Frame;
use React\EventLoop\LoopInterface;
use React\Socket\Connector;
use React\Stream\ReadableStreamInterface;
class HttpClient
{
@@ -84,22 +86,17 @@ class HttpClient
protected function sendRequestToApplication(RequestInterface $request, $proxyConnection = null)
{
(new Browser($this->loop, $this->createConnector()))
->withOptions([
'followRedirects' => false,
'obeySuccessCode' => false,
'streaming' => true,
])
->send($request)
->withFollowRedirects(false)
->withRejectErrorResponse(false)
->requestStreaming($request->getMethod(), $this->getExposeUri($request), $request->getHeaders(), $request->getBody())
->then(function (ResponseInterface $response) use ($proxyConnection) {
if (! isset($response->buffer)) {
$response = $this->rewriteResponseHeaders($response);
$response->buffer = str($response);
}
$this->sendChunkToServer($response->buffer, $proxyConnection);
/* @var $body \React\Stream\ReadableStreamInterface */
/* @var $body ReadableStreamInterface */
$body = $response->getBody();
$this->logResponse(str($response));
@@ -136,24 +133,14 @@ class HttpClient
return Request::fromString($data);
}
protected function rewriteResponseHeaders(ResponseInterface $response)
private function getExposeUri(RequestInterface $request): UriInterface
{
if (! $response->hasHeader('Location')) {
return $response;
}
$exposeProto = $request->getHeader('x-expose-proto')[0];
$exposeHost = explode(':', $request->getHeader('x-expose-host')[0]);
$location = $response->getHeaderLine('Location');
if (! strstr($location, $this->connectionData->host)) {
return $response;
}
$location = str_replace(
$this->connectionData->host,
$this->configuration->getUrl($this->connectionData->subdomain),
$location
);
return $response->withHeader('Location', $location);
return $request->getUri()
->withScheme($exposeProto)
->withHost($exposeHost[0])
->withPort($exposeHost[1]);
}
}

View File

@@ -45,15 +45,13 @@ class ConnectionManager implements ConnectionManagerContract
public function storeConnection(string $host, ?string $subdomain, ConnectionInterface $connection): ControlConnection
{
$clientId = (string) uniqid();
$connection->client_id = $clientId;
$connection->client_id = sha1(uniqid('', true));
$storedConnection = new ControlConnection(
$connection,
$host,
$subdomain ?? $this->subdomainGenerator->generateSubdomain(),
$clientId,
$connection->client_id,
$this->getAuthTokenFromConnection($connection)
);

View File

@@ -113,9 +113,13 @@ class TunnelMessageController extends Controller
$host .= ":{$this->configuration->port()}";
}
$request->headers->set('Host', $controlConnection->host);
$exposeUrl = parse_url($controlConnection->host);
$request->headers->set('Host', "{$controlConnection->subdomain}.{$host}");
$request->headers->set('X-Forwarded-Proto', $request->isSecure() ? 'https' : 'http');
$request->headers->set('X-Expose-Request-ID', uniqid());
$request->headers->set('X-Expose-Request-ID', sha1(uniqid('', true)));
$request->headers->set('X-Expose-Host', sprintf('%s:%s', $exposeUrl['host'], $exposeUrl['port']));
$request->headers->set('X-Expose-Proto', $exposeUrl['scheme']);
$request->headers->set('Upgrade-Insecure-Requests', 1);
$request->headers->set('X-Exposed-By', config('app.name').' '.config('app.version'));
$request->headers->set('X-Original-Host', "{$controlConnection->subdomain}.{$host}");