This repository was archived by the owner on Aug 25, 2021. It is now read-only.
Feat/refactor http hook#244
Open
myfjdthink wants to merge 4 commits into
Open
Conversation
Codecov Report
@@ Coverage Diff @@
## master #244 +/- ##
==========================================
- Coverage 80.7% 80.63% -0.07%
==========================================
Files 190 190
Lines 6415 6415
Branches 870 866 -4
==========================================
- Hits 5177 5173 -4
- Misses 853 856 +3
- Partials 385 386 +1
Continue to review full report at Codecov.
|
Member
|
逻辑调整我看下,这块以后会通过规范调整 |
Member
|
下周估计规范接口会集成进来,到时候一起改掉吧 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
我拓展了 HttpServerPatcher 和 HttpClientPatcher,让这两个 Hook 都能记录 query、data 和 response。
具体实现可见:
https://github.com/kaolalicai/klg-tracer/blob/master/src/patch/HttpServer.ts
https://github.com/kaolalicai/klg-tracer/blob/master/src/patch/shimmers/http-client/Shimmer.ts
拓展的过程有些小麻烦,主要是上述两个组件的代码结构会有不方便拓展的地方,导致我不能简单复写某些方法,表现有:
1 HttpServerPatcher.shimmer 函数过长,如果要替换其中某段逻辑不方便
2 KlgHttpClientShimmer.wrapRequest 是以成员属性的方式定义的,overwrite 后 super.wrapRequest 会有问题。
除了拓展的问题,我在整理代码的时候发现像
这类的钩子其实可以直接用事件监听来实现, 如下,而且没问题,测试通过
针对上述问题,我按照我的想法把 HttpServer 和 KlgHttpClientShimmer 整理了一遍,勉强做个抽象,发了个 PR,供参考。
HttpServer 大致代码结构:
KlgHttpClientShimmer 大致代码结构: