Skip to content

Commit

Permalink
new version
Browse files Browse the repository at this point in the history
  • Loading branch information
phphleb committed Dec 12, 2024
1 parent 99cc546 commit 65c017f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
24 changes: 13 additions & 11 deletions HlebAsyncBootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ protected function buildRequest(?object $request = null): SystemRequest
$rawBody = isset($body) && \is_string($body) ? $body : null;
$parsedBody = isset($body) && \is_array($body) ? $body : null;

$_SERVER['REMOTE_ADDR'] = \strip_tags((string)$_SERVER['REMOTE_ADDR']);

return new SystemRequest(
(array)$_COOKIE,
$rawBody,
Expand Down Expand Up @@ -351,12 +353,14 @@ protected function parsePsr7Request(object $req): array
isset($_SERVER['DOCUMENT_URI']) or $_SERVER['DOCUMENT_URI'] = $uri->getPath();
isset($_SERVER['SERVER_NAME']) or $_SERVER['SERVER_NAME'] = $uri->getHost();
isset($_SERVER['QUERY_STRING']) or $_SERVER['QUERY_STRING'] = $uri->getQuery();
isset($_SERVER['REMOTE_ADDR']) or $_SERVER['REMOTE_ADDR'] = $uri->getScheme();
isset($_SERVER['SERVER_PORT']) or $_SERVER['SERVER_PORT'] = $uri->getPort();
isset($_SERVER['REQUEST_URI']) or $_SERVER['REQUEST_URI'] = $uri->getPath() . '?' .
\ltrim($uri->getQuery(), '?/');
if (empty($_SERVER['REMOTE_ADDR'])) {
$params = $uri->getServerParams();
$_SERVER['REMOTE_ADDR'] = (string)($params['REMOTE_ADDR'] ?? $params['HTTP_CLIENT_IP'] ?? $params['HTTP_X_FORWARDED_FOR'] ?? null);
}
}

return [$body, $headers];
}

Expand All @@ -376,12 +380,14 @@ protected function parseSwooleRequest(object $req): array
$_GET = $req->get ?? [];
$_FILES = $req->files ?? [];
$_SERVER['HTTP_HOST'] = $server['remote_addr'] ?? $headers['host'];
$_SERVER['REMOTE_ADDR'] = $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
$_SERVER['REMOTE_ADDR'] = $server['remote_addr'] ?? '';
$_SERVER['REQUEST_METHOD'] = \strtoupper((string)$server['request_method']);
$_SERVER['DOCUMENT_URI'] = $server['path_info'] ?? '';
$_SERVER['SERVER_PORT'] = $server['server_port'] ?? null;
$_SERVER['QUERY_STRING'] = $server['query_string'] ?? '';
$_SERVER['REQUEST_URI'] = $server['request_uri'] ?? '';
$_SERVER["SERVER_PROTOCOL"] = $server['server_protocol'] ?? 'HTTP/1.1';

$_SERVER['HTTPS'] = $_SERVER['SERVER_PORT'] == 443 ? 'on' : 'off';
// An additional field by which you can get the type of HTTP connection scheme.
Expand All @@ -403,22 +409,18 @@ protected function parseSwooleRequest(object $req): array
*/
protected function parseWorkermanRequest(object $req): array
{
$hostData = \explode($req->host(true), ':');
$host = \array_shift($hostData);
$port = $hostData? (int)$hostData[0] : null;
// Override $_SERVER['HTTP_HOST'] on initialization if it's different.
// Переопределите $_SERVER['HTTP_HOST'] при инициализации, если он отличается.
$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_HOST'] ?? $req->host(true);
$_SERVER['REMOTE_ADDR'] = $_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
$_SERVER['REMOTE_ADDR'] = $req->connection?->getRemoteIp();
$get = $req->get() ?: [];
$_GET = $get;
$_POST = $req->post() ?: [];
$_SERVER['QUERY_STRING'] = $get ? '?' . \http_build_query($get) : '';
$_SERVER['REQUEST_METHOD'] = \strtoupper((string)$req->method());
$_SERVER['DOCUMENT_URI'] = $req->uri() ?: '';
// Override $_SERVER['SERVER_PORT'] on initialization if it's different.
// Переопределите $_SERVER['SERVER_PORT'] при инициализации, если он отличается.
$_SERVER['SERVER_PORT'] = $_SERVER['SERVER_PORT'] ?? $port;
$_SERVER['SERVER_PORT'] = $_SERVER['SERVER_PORT'] ?? $req->connection?->getLocalPort();
$_SERVER['REQUEST_URI'] = $_SERVER['DOCUMENT_URI'] . $_SERVER['QUERY_STRING'];
$_SERVER['HTTPS'] = $_SERVER['HTTPS'] ?? ($_SERVER['SERVER_PORT'] == 443 ? 'on' : 'off');
$_SERVER["SERVER_PROTOCOL"] = 'HTTP/' . $req->protocolVersion();
Expand All @@ -441,7 +443,7 @@ protected function parseHeaders(mixed $headers, string $class): array
{
$headers = (new $class())->update($headers);

return array_change_key_case($headers, CASE_LOWER);
return \array_change_key_case($headers, CASE_LOWER);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions HlebBootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class HlebBootstrap

final public const ASYNC_MODE = 3;

final protected const DEFAULT_RE_CLEANING = 10_000;
final protected const DEFAULT_RE_CLEANING = 100_000;

protected ?int $mode = null;

Expand Down Expand Up @@ -108,7 +108,7 @@ public function __construct(?string $publicPath = null, array $config = [], ?Log

// The current version of the framework.
// Текущая версия фреймворка.
\defined('HLEB_CORE_VERSION') or \define('HLEB_CORE_VERSION', '2.0.54');
\defined('HLEB_CORE_VERSION') or \define('HLEB_CORE_VERSION', '2.0.56');

$this->logger = $logger;

Expand Down
2 changes: 1 addition & 1 deletion Init/Review/basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function env_array(string $name, #[SensitiveParameter] array $default): array
return $default;
}
if (str_starts_with($env, '{') && str_ends_with($env,'}')) {
return json_decode($env, true, JSON_THROW_ON_ERROR);
return json_decode($env, true, JSON_THROW_ON_ERROR);
}
throw new RuntimeException("The value of the environment variable `{$name}` is expected to be an JSON string!");
}
Expand Down

0 comments on commit 65c017f

Please sign in to comment.