Fix issues with assets and remote host as envvar (PHP_PROXY_REMOTEHOST)

This commit is contained in:
Simon Vieille 2017-11-08 20:34:48 +01:00
parent d2d3486414
commit 0d74eaa1eb
No known key found for this signature in database
GPG Key ID: 919533E2B946EA10
1 changed files with 12 additions and 5 deletions

View File

@ -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();