changes for filter and print

This commit is contained in:
2024-09-29 16:59:27 +05:45
parent 497f567cba
commit 684e01bf48
1335 changed files with 38709 additions and 74987 deletions

View File

@ -12,11 +12,11 @@ use Psr\Http\Message\StreamInterface;
*/
trait MessageTrait
{
/** @var array<string, string[]> Map of all registered headers, as original name => array of values */
/** @var string[][] Map of all registered headers, as original name => array of values */
private $headers = [];
/** @var array<string, string> Map of lowercase header name => original name at registration */
private $headerNames = [];
/** @var string[] Map of lowercase header name => original name at registration */
private $headerNames = [];
/** @var string */
private $protocol = '1.1';
@ -37,6 +37,7 @@ trait MessageTrait
$new = clone $this;
$new->protocol = $version;
return $new;
}
@ -135,11 +136,12 @@ trait MessageTrait
$new = clone $this;
$new->stream = $body;
return $new;
}
/**
* @param array<string|int, string|string[]> $headers
* @param (string|string[])[] $headers
*/
private function setHeaders(array $headers): void
{
@ -191,7 +193,7 @@ trait MessageTrait
*
* @return string[] Trimmed header values
*
* @see https://tools.ietf.org/html/rfc7230#section-3.2.4
* @see https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.4
*/
private function trimAndValidateHeaderValues(array $values): array
{
@ -211,7 +213,7 @@ trait MessageTrait
}
/**
* @see https://tools.ietf.org/html/rfc7230#section-3.2
* @see https://datatracker.ietf.org/doc/html/rfc7230#section-3.2
*
* @param mixed $header
*/
@ -224,18 +226,15 @@ trait MessageTrait
));
}
if (! preg_match('/^[a-zA-Z0-9\'`#$%&*+.^_|~!-]+$/', $header)) {
if (!preg_match('/^[a-zA-Z0-9\'`#$%&*+.^_|~!-]+$/D', $header)) {
throw new \InvalidArgumentException(
sprintf(
'"%s" is not valid header name',
$header
)
sprintf('"%s" is not valid header name.', $header)
);
}
}
/**
* @see https://tools.ietf.org/html/rfc7230#section-3.2
* @see https://datatracker.ietf.org/doc/html/rfc7230#section-3.2
*
* field-value = *( field-content / obs-fold )
* field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
@ -257,8 +256,10 @@ trait MessageTrait
// Clients must not send a request with line folding and a server sending folded headers is
// likely very rare. Line folding is a fairly obscure feature of HTTP/1.1 and thus not accepting
// folding is not likely to break any legitimate use case.
if (! preg_match('/^[\x20\x09\x21-\x7E\x80-\xFF]*$/', $value)) {
throw new \InvalidArgumentException(sprintf('"%s" is not valid header value', $value));
if (!preg_match('/^[\x20\x09\x21-\x7E\x80-\xFF]*$/D', $value)) {
throw new \InvalidArgumentException(
sprintf('"%s" is not valid header value.', $value)
);
}
}
}