Bicycle/System/Classes/HTTP.php
Egor Isaev b516ca07dc Initial commit: Bicycle PHP MVC micro-framework
Core MVC, HTTP client, Session, Cookie, Config, HTTPException — 111 PHPUnit tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-04 10:04:19 +03:00

47 lines
1.1 KiB
PHP

<?php
/**
* @package Bicycle
* @author Egor Isaev
* @description HTTP.php
* @copyright (c) 04/06/2026
*/
namespace System\Classes;
use System\Classes\HTTP\Header;
class HTTP
{
public static function redirect(string $uri, int $code = 302): never
{
http_response_code($code);
header('Location: ' . $uri);
exit;
}
public static function request_headers(): Header
{
if (function_exists('apache_request_headers')) {
return new Header(array_change_key_case(apache_request_headers()));
}
$headers = [];
if (!empty($_SERVER['CONTENT_TYPE'])) {
$headers['content-type'] = $_SERVER['CONTENT_TYPE'];
}
if (!empty($_SERVER['CONTENT_LENGTH'])) {
$headers['content-length'] = $_SERVER['CONTENT_LENGTH'];
}
foreach ($_SERVER as $key => $value) {
if (str_starts_with($key, 'HTTP_')) {
$headers[str_replace('_', '-', strtolower(substr($key, 5)))] = $value;
}
}
return new Header($headers);
}
}