christoph-kluge/reactphp-http-response-compression-middleware 问题修复 & 功能扩展

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

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

christoph-kluge/reactphp-http-response-compression-middleware

Composer 安装命令:

composer require christoph-kluge/reactphp-http-response-compression-middleware

包简介

A response compression middleware for the ReactPHP HTTP-Server

README 文档

README

Build Status Total Downloads License

Install

To install via Composer, use the command below, it will automatically detect the latest version and bind it with ^.

composer require christoph-kluge/reactphp-http-response-compression-middleware

This middleware will detect if the request is compressible and will compress the response body and add relevant headers to it. Heavy lifting is done by clue/php-zlib-react, thanks!

Usage

$server = new Server(new MiddlewareRunner([
    new ResponseCompressionMiddleware([
        new CompressionGzipHandler(),
        new CompressionDeflateHandler(),
    ]),
    function (ServerRequestInterface $request, callable $next) {
        return new Response(200, ['Content-Type' => 'application/json'], json_encode([
            'some' => 'nice',
            'json' => 'values',
        ]));
    },
]));

Response-detection for compressible mime/content-types

Default detection

The default handlers will use by default the DefaultRegexDetecor to identify compressible Content-Types by a set of regular expressions. Those regular expressions are:

// DefaultRegexDetector.php -> used in __construct()

new RegexDetector([
    '/^text\/[a-z-\+]+$/', // text/*
    '/^application\/json$/', // application/json
    '/^application\/xml$/', // application/xml
    '/^[a-z-\+]+\/[a-z-\+]+\+json$/', // */*+json
    '/^[a-z-\+]+\/[a-z-\+]+\+xml$/', // */*+xml
]);

Available Detectors

There are currently the following available detectors:

  • ArrayDetector: Which will accept an whitelist of mime-types to check against
  • RegexDetecor: Which will accept an whitelist of regular expressions to check against
new CompressionGzipHandler(new ArrayDetector[
    'text/html',
]),
new CompressionGzipHandler(new RegexDetector[
    '/^text\/[a-z]+$/',
]),

Want to implement custom detectors?

If you would like to add a custom detection for the response mime type then you can simply pass an object as first parameter which implements the MimeDetectorInterface.

new CompressionGzipHandler(new class implements MimeDetectorInterface {
    public function isCompressible($mime) {
        // your custom magic here..
        return true;
    }
}),

License

The MIT License (MIT)

Copyright (c) 2017 Christoph Kluge

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

christoph-kluge/reactphp-http-response-compression-middleware 适用场景与选型建议

christoph-kluge/reactphp-http-response-compression-middleware 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.84k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2017 年 10 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 christoph-kluge/reactphp-http-response-compression-middleware 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 christoph-kluge/reactphp-http-response-compression-middleware 我们能提供哪些服务?
定制开发 / 二次开发

基于 christoph-kluge/reactphp-http-response-compression-middleware 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-10-02