0

Final Class Yiisoft\HttpMiddleware\HttpCache\ETagValueNormalizer\SuffixETagValueNormalizer

InheritanceYiisoft\HttpMiddleware\HttpCache\ETagValueNormalizer\SuffixETagValueNormalizer
ImplementsYiisoft\HttpMiddleware\HttpCache\ETagValueNormalizer\ETagValueNormalizerInterface

Removes a suffix from ETag values.

This is useful for normalizing ETag values modified by web server compression modules. For example, Apache mod_deflate and mod_brotli append -gzip and -br suffixes to the ETag header value (see {@link https://httpd.apache.org/docs/2.4/mod/mod_deflate.html#deflatealteretag}).

Only the first matching suffix is removed. For example, for value content-gzip-br and suffixes ['-gzip', '-br'], the result is content-gzip.

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string|string[] $suffix )
$suffix string|string[]

A single suffix or a list of suffixes to remove from ETag values.

                public function __construct(string|array $suffix)
{
    $this->suffixes = (array) $suffix;
}

            
normalize() public method

public string normalize ( string $value )
$value string

                public function normalize(string $value): string
{
    foreach ($this->suffixes as $suffix) {
        if ($suffix !== '' && str_ends_with($value, $suffix)) {
            return substr($value, 0, -strlen($suffix));
        }
    }
    return $value;
}