Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow client code configure its own GuzzleHTTP handler #578

Merged
merged 2 commits into from
Jan 24, 2017

Conversation

acgrid
Copy link
Contributor

@acgrid acgrid commented Jan 24, 2017

这个PR希望允许客户端代码添加自定义GuzzleHTTP中间件。

一个现实情景是,希望获知不同HTTP API的使用情况,以免碰到次数限制。附带的测试就是用这个需求来模拟的。

虽然EasyWeChat\Core\HTTP实例可以通过AbstractAPI::getHttp()获得,但只适合访问个别组件的情况。鉴于handler本身也是GuzzleHttp\Http的options之一,所以想到利用相同的key为客户端提供设置默认设置的机会。当然GuzzleHttp\Http期望实际类型是GuzzleHttp\HandlerStack,客户端需要自行保证callable的正确性,好在可以用GuzzleHttp\Middleware提供的工厂方法。

写测试的时候头疼了一个小时,难写的测试往往提示实现不科学。感谢赐教!

@acgrid acgrid force-pushed the allow-guzzle-user-handler branch 2 times, most recently from 4f679d8 to 7d2febf Compare January 24, 2017 08:30
@acgrid acgrid force-pushed the allow-guzzle-user-handler branch from 7d2febf to e1b6b6f Compare January 24, 2017 08:33
@overtrue overtrue merged commit f57b121 into w7corp:master Jan 24, 2017
@acgrid acgrid deleted the allow-guzzle-user-handler branch January 24, 2017 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants