Allow client code configure its own GuzzleHTTP handler #578
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
这个PR希望允许客户端代码添加自定义GuzzleHTTP中间件。
一个现实情景是,希望获知不同HTTP API的使用情况,以免碰到次数限制。附带的测试就是用这个需求来模拟的。
虽然
EasyWeChat\Core\HTTP
实例可以通过AbstractAPI::getHttp()
获得,但只适合访问个别组件的情况。鉴于handler本身也是GuzzleHttp\Http
的options之一,所以想到利用相同的key为客户端提供设置默认设置的机会。当然GuzzleHttp\Http
期望实际类型是GuzzleHttp\HandlerStack
,客户端需要自行保证callable的正确性,好在可以用GuzzleHttp\Middleware
提供的工厂方法。写测试的时候头疼了一个小时,难写的测试往往提示实现不科学。感谢赐教!