diff --git a/index.php b/index.php index 8803a58..f246881 100644 --- a/index.php +++ b/index.php @@ -18,10 +18,15 @@ function sendResponse(Response $response) http_response_code($response->getStatusCode()); foreach ($response->getHeaders() as $header => $values) { - header(sprintf('%s: %s'."\n", $header, implode(', ', $values))); + if (strtolower($header) === 'content-type') { + header(sprintf('%s: %s', $header, implode('; ', $values))); + } } - echo $response->getBody(); + $body = $response->getBody(); + echo $body; + + return $body; } /** @@ -32,7 +37,7 @@ function sendResponse(Response $response) * * @return \GuzzleHttp\Psr7\Response */ -function doRequest(ServerRequest $request, Client $client) +function doRequest(ServerRequest $request, Client $client, $host) { $headers = []; @@ -41,7 +46,8 @@ function doRequest(ServerRequest $request, Client $client) } $serverParams = $request->getServerParams(); - $url = sprintf('https://gitnet.fr%s', $serverParams['PATH_INFO'] ?? $serverParams['REQUEST_URI']); + $path = !empty($serverParams['PATH_INFO']) ? $serverParams['PATH_INFO'] : $serverParams['REQUEST_URI']; + $url = $host.$path; unset($headers['host']); @@ -58,7 +64,8 @@ function doRequest(ServerRequest $request, Client $client) try { $apiResponse = doRequest( ServerRequestFactory::fromGlobals(), - new Client() + new Client(), + getenv('PHP_PROXY_REMOTEHOST') ); } catch (ClientException $e) { $apiResponse = $e->getResponse();