green-turtle / content-encoding
此包最新版本(1.0.0)的许可证信息不可用。
1.0.0
2023-12-12 18:21 UTC
Requires
- php: ^8.1.0
- ext-zlib: *
- illuminate/http: ^9.0 || ^10.0
- illuminate/support: ^9.0 || ^10.0
- symfony/psr-http-message-bridge: ^2.1
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^3.7
README
编码响应内容的中间件。
减少发送的数据,减少使用的带宽。
安装
composer require green-turtle/content-encoding
配置
默认设置在 config/content-encoding.php
中。
要发布到您自己的配置中,请使用以下命令
php artisan vendor:publish --tag="green-turtle-content-encoding"
编码未知类型
有时可能会缺少 Content-Type
标头。您可以在配置中指定是否仍希望尝试编码数据。
默认设置为 false。
'encode_unknown_type' => false,
允许类型
以下是允许编码的内容类型。
每个类型都是一个将用作正则表达式模式的字符串。
例如,任何文本格式都是可接受的
'allowed_types' => [ '#^(text\/.*)(;.*)?$#' ]
编码器
这些编码器确定支持哪些编码。
默认启用内置编码器
'encoders' => [ Gzip::class, Deflate::class, ]
您可以通过实现以下接口创建更多
GreenTurtle\Middleware\Encoder\ContentEncoder
全局使用
要全局启用此中间件,请将以下内容添加到 middleware
数组中,该数组位于 app/Http/Kernel.php
中
例如
protected $middleware = [ // other middleware... \GreenTurtle\Middleware\ContentEncoding::class // other middleware... ];