Change of condition "content-type"

This commit is contained in:
2025-09-13 14:56:51 +05:00
parent c841250933
commit e93ea5825e

View File

@@ -6,16 +6,16 @@ namespace mirzaev\minimal\http;
// Files of the project // Files of the project
use mirzaev\minimal\http\enumerations\method, use mirzaev\minimal\http\enumerations\method,
mirzaev\minimal\http\enumerations\protocol, mirzaev\minimal\http\enumerations\protocol,
mirzaev\minimal\http\enumerations\status, mirzaev\minimal\http\enumerations\status,
mirzaev\minimal\http\enumerations\content, mirzaev\minimal\http\enumerations\content,
mirzaev\minimal\http\response; mirzaev\minimal\http\response;
// Built-in libraries // Built-in libraries
use DomainException as exception_domain, use DomainException as exception_domain,
InvalidArgumentException as exception_argument, InvalidArgumentException as exception_argument,
RuntimeException as exception_runtime, RuntimeException as exception_runtime,
LogicException as exception_logic; LogicException as exception_logic;
/** /**
* Request * Request
@@ -324,13 +324,16 @@ final class request
bool $environment = false bool $environment = false
) { ) {
// Writing method from argument into the property // Writing method from argument into the property
if (isset($method)) $this->method = $method; if (isset($method))
$this->method = $method;
// Writing URI from argument into the property // Writing URI from argument into the property
if (isset($uri)) $this->uri = $uri; if (isset($uri))
$this->uri = $uri;
// Writing verstion of HTTP protocol from argument into the property // Writing verstion of HTTP protocol from argument into the property
if (isset($protocol)) $this->protocol = $protocol; if (isset($protocol))
$this->protocol = $protocol;
if (isset($headers)) { if (isset($headers)) {
// Received headers // Received headers
@@ -363,10 +366,12 @@ final class request
} }
// Writing parameters from argument into the property // Writing parameters from argument into the property
if (isset($parameters)) $this->parameters = $parameters; if (isset($parameters))
$this->parameters = $parameters;
// Writing files from argument into the property // Writing files from argument into the property
if (isset($files)) $this->files = $files; if (isset($files))
$this->files = $files;
if ($environment) { if ($environment) {
// Requested to write values from environment // Requested to write values from environment
@@ -410,7 +415,7 @@ final class request
unset($buffer); unset($buffer);
} }
if (str_starts_with($this->headers['content-type'], content::json->value)) { if (str_starts_with($this->headers['content-type'] ?? '', content::json->value)) {
// The body contains "application/json" // The body contains "application/json"
// Initializing data from the input buffer // Initializing data from the input buffer
@@ -467,8 +472,10 @@ final class request
} }
// Validating of required properties // Validating of required properties
if (empty($this->method)) throw new exception_argument('Failed to initialize method of the request', status::internal_server_error->value); if (empty($this->method))
if (empty($this->uri)) throw new exception_argument('Failed to initialize URI of the request', status::internal_server_error->value); throw new exception_argument('Failed to initialize method of the request', status::internal_server_error->value);
if (empty($this->uri))
throw new exception_argument('Failed to initialize URI of the request', status::internal_server_error->value);
} }
/** /**