middlewares/encoder 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

middlewares/encoder

最新稳定版本:v2.2.0

Composer 安装命令:

composer require middlewares/encoder

包简介

Middleware to encode the response body to gzip or deflate

README 文档

README

Latest Version on Packagist Software License Testing Total Downloads

Middleware to encode the response body to gzip or deflate if the Accept-Encoding header is present and adds the Content-Encoding header. This package is splitted into the following components:

You can use the component ContentEncoding in the middlewares/negotiation to negotiate the encoding to use.

Requirements

Installation

This package is installable and autoloadable via Composer as middlewares/encoder.

composer require middlewares/encoder

GzipEncoder

Compress the response body to GZIP format using gzencode and add the header Content-Encoding: gzip.

Note: The response body is encoded only if the header contains the value gzip in the header Accept-Encoding.

Dispatcher::run([
	new Middlewares\GzipEncoder(),
]);

Optionally, you can provide a Psr\Http\Message\StreamFactoryInterface that will be used to create the response body. If it's not defined, Middleware\Utils\Factory will be used to detect it automatically.

$streamFactory = new MyOwnStreamFactory();

$encoder = new Middlewares\GzipEncoder($streamFactory);

DeflateEncoder

Compress the response body to Deflate format using gzdeflate and add the header Content-Encoding: deflate.

Note: The response body is encoded only if the header contains the value deflate in the header Accept-Encoding.

Dispatcher::run([
	new Middlewares\DeflateEncoder(),
]);

Optionally, you can provide a Psr\Http\Message\StreamFactoryInterface that will be used to create the response body. If it's not defined, Middleware\Utils\Factory will be used to detect it automatically.

$streamFactory = new MyOwnStreamFactory();

$encoder = new Middlewares\DeflateEncoder($streamFactory);

Common Options

contentType

This option allows the overring of the default patterns used to detect what resources are already compressed.

The default pattern detects the following mime types text/*, application/json, image/svg+xml and empty content types as compressible. If the pattern begins with a forward slash / it is tested as a regular expression, otherwise its is case-insensitive string comparison.

Dispatcher::run([
	(new Middlewares\DeflateEncoder())
            ->contentType(
                    '/^application\/pdf$/', // Regular Expression
                    'text/csv' // Text Pattern
            )
]);

Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.

The MIT License (MIT). Please see LICENSE for more information.

统计信息

  • 总下载量: 128.13k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 3
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 未知

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固