This repository has been archived by the owner on Aug 25, 2021. It is now read-only.
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 大致代码结构: