guzzlehttp/message-integrity-subscriber
最新稳定版本:0.2.0
Composer 安装命令:
composer require guzzlehttp/message-integrity-subscriber
包简介
Verifies the integrity of HTTP responses using customizable validators (Guzzle 4+)
README 文档
README
Verifies the integrity of HTTP responses using customizable validators.
This plugin can be used, for example, to validate the message integrity of
responses based on the Content-MD5 header. The plugin offers a convenience
method for validating a Content-MD5 header.
use GuzzleHttp\Client(); use GuzzleHttp\Subscriber\MessageIntegrity\ResponseIntegrity; $subscriber = ResponseIntegrity::createForContentMd5(); $client = new Client(); $client->getEmitter()->attach($subscriber);
Installing
This project can be installed using Composer. Add the following to your composer.json:
{
"require": {
"guzzlehttp/message-integrity-subscriber": "0.2.*"
}
}
Constructor Options
The GuzzleHttp\Subscriber\MessageIntegrity\ResponseIntegrity class
accepts an associative array of options:
- expected
- (callable) A function that returns the hash that is expected for a response. The function accepts a ResponseInterface objects and returns a string that is compared against the calculated rolling hash.
- hash
- (
GuzzleHttp\Subscriber\MessageIntegrity\HashInterface) A hash object used to compute a hash of the response body. The result created by the has is then compared against the extracted header value. - size_cutoff
- (integer) If specified, the message integrity will only be validated if the
response size is less than the
size_cutoffvalue (in bytes).
use GuzzleHttp\Client(); use GuzzleHttp\Message\ResponseInterface; use GuzzleHttp\Subscriber\MessageIntegrity\ResponseIntegrity; $subscriber = new ResponseIntegrity([ 'hash' => new PhpHash('md5', ['base64' => true]) 'expected' => function (ResponseInterface $response) { return $response->getHeader('Content-MD5'); } ]); $client = new Client(); $client->getEmitter()->attach($subscriber);
Handling Errors
If the calculated hash of the response body does not match the extracted
response's header, then a GuzzleHttp\Subscriber\MessageIntegrity\MessageIntegrityException
is thrown. This exception extends from GuzzleHttp\Exception\RequestException
so it contains a request accessed via getRequest() and a response via
getResponse().
use GuzzleHttp\Client(); use GuzzleHttp\Subscriber\MessageIntegrity\ResponseIntegrity; use GuzzleHttp\Subscriber\MessageIntegrity\MessageIntegrityException; $subscriber = ResponseIntegrity::createForContentMd5(); $client = new Client(); $client->getEmitter()->attach($subscriber); try { $client->get('http://httpbin.org/get'); } catch (MessageIntegrityException $e) { echo $e->getRequest() . "\n"; echo $e->getResponse() . "\n"; }
Limitations
- Only works with seekable responses or streaming responses.
- Does not currently work with responses that use a
Transfer-Encodingheader. - Does not currently work with responses that use a
Content-Encodingheader.
guzzlehttp/message-integrity-subscriber 适用场景与选型建议
guzzlehttp/message-integrity-subscriber 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.58k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2014 年 03 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「http」 「Guzzle」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 guzzlehttp/message-integrity-subscriber 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 guzzlehttp/message-integrity-subscriber 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 guzzlehttp/message-integrity-subscriber 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
统计信息
- 总下载量: 14.58k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 28
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-03-01