80 lines
1.5 KiB
PHP
80 lines
1.5 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace alveolata\cgi;
|
||
|
|
||
|
// require_once(DIR_ALVEOLATA . '/definitions.php');
|
||
|
require_once(DIR_ALVEOLATA . '/cookie/functions.php');
|
||
|
require_once(DIR_ALVEOLATA . '/http/types.php');
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @author Christian Fraß <frass@greenscale.de>
|
||
|
*/
|
||
|
function get_http_request(
|
||
|
): \alveolata\http\struct_request
|
||
|
{
|
||
|
/*
|
||
|
\alveolata\log\debug(
|
||
|
'superglobals',
|
||
|
[
|
||
|
'server' => $_SERVER,
|
||
|
'cookie' => \json_encode($_COOKIE),
|
||
|
]
|
||
|
);
|
||
|
*/
|
||
|
$cookiedata = (
|
||
|
isset($_SERVER['HTTP_COOKIE'])
|
||
|
? \alveolata\cookie\decode($_SERVER['HTTP_COOKIE'])
|
||
|
: null
|
||
|
);
|
||
|
$request = new \alveolata\http\struct_request(
|
||
|
$_SERVER['SERVER_PROTOCOL'],
|
||
|
($_SERVER['REQUEST_METHOD'] ?? 'POST'),
|
||
|
$_SERVER['REQUEST_URI'],
|
||
|
\array_merge(
|
||
|
\getallheaders(),
|
||
|
[
|
||
|
'Cookie' => ($_SERVER['HTTP_COOKIE'] ?? null),
|
||
|
'Content-Type' => ($_SERVER['CONTENT_TYPE'] ?? 'application/json'),
|
||
|
],
|
||
|
),
|
||
|
\file_get_contents('php://input')
|
||
|
);
|
||
|
return $request;
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @author Christian Fraß <frass@greenscale.de>
|
||
|
*/
|
||
|
function setup(
|
||
|
): void
|
||
|
{
|
||
|
while (ob_get_level() >= 1) {
|
||
|
ob_end_clean();
|
||
|
}
|
||
|
ob_start();
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @author Christian Fraß <frass@greenscale.de>
|
||
|
*/
|
||
|
function put_http_response(
|
||
|
\alveolata\http\struct_response $response
|
||
|
): void
|
||
|
{
|
||
|
while (ob_get_level() >= 1) {
|
||
|
ob_end_clean();
|
||
|
}
|
||
|
ob_start();
|
||
|
foreach ($response->headers as $key => $value) {
|
||
|
\header(\sprintf('%s: %s', $key, $value));
|
||
|
}
|
||
|
\http_response_code($response->statuscode);
|
||
|
\file_put_contents('php://output', $response->body);
|
||
|
ob_end_flush();
|
||
|
}
|
||
|
|
||
|
?>
|