green-turtle / content-encoding

此包最新版本(1.0.0)的许可证信息不可用。

1.0.0 2023-12-12 18:21 UTC

This package is auto-updated.

Last update: 2024-09-13 16:17:20 UTC


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...
];