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

功能扩展的问题 #10

Closed
tensorZhang opened this issue Dec 24, 2017 · 18 comments
Closed

功能扩展的问题 #10

tensorZhang opened this issue Dec 24, 2017 · 18 comments

Comments

@tensorZhang
Copy link

tensorZhang commented Dec 24, 2017

proxyee代理服务试用了,感觉挺不错的。希望能用proxyee拦截打印出http请求的参数,和代理服务响应的参数。请问下monkeyWie,后面有没有考虑做这方面的功能扩展?或者能不能给我建议下如何实现这样的功能?谢谢!
主要是Content里面的内容不知道如何读取。

@Rekoe
Copy link

Rekoe commented Dec 24, 2017

@tensorZhang HttpProxyIntercept 这个类的方法就是解决你的需求的实现

@tensorZhang tensorZhang reopened this Dec 24, 2017
@tensorZhang
Copy link
Author

tensorZhang commented Dec 24, 2017

@Rekoe 多谢!我是这样拦截响应content的。用httpContent.copy();使response能够继续返回给客户端。不知这种用法是否优雅?
image

@monkeyWie
Copy link
Owner

monkeyWie commented Dec 24, 2017

@tensorZhang
因为有些响应头太大了,如果直接把响应体全部加载在内存里可能会导致内存溢出的,所以这个还是要靠自己根据情况来特殊处理的。
可以看看我的proxyee-down项目里,用拦截器来修改响应体的方式https://github.com/monkeyWie/proxyee-down/blob/dev/src/main/java/lee/study/down/intercept/common/ResponseTextIntercept.java

缓存一个ByteBuf在Intercept里,然后每次有HttpContent进来都写进缓存里,在LastHttpContent 时候就可以解码拿到所有的content了,里面还有对gizp的特殊处理

@Rekoe
Copy link

Rekoe commented Dec 24, 2017

@monkeyWie 好的 谢谢 就是想要这个这样的效果 我先参照看看
@tensorZhang 你那种方式会有问题 你看我#9里面的那个问题,问题就是那个结果

@monkeyWie
Copy link
Owner

@Rekoe 嗯嗯,有问题可以随时交流~

@Rekoe
Copy link

Rekoe commented Dec 24, 2017

@monkeyWie 刚看了下 ResponseTextIntercept 中的 public void afterResponse(Channel clientChannel, Channel proxyChannel, HttpContent httpContent, HttpProxyInterceptPipeline pipeline) throws Exception {....} 代码 这个是把多次的响应数据收集到一个bytebuf 中 最后通过 DefaultLastHttpContent响应出去的么

@monkeyWie
Copy link
Owner

monkeyWie commented Dec 24, 2017

@Rekoe 是的,把所有的content缓存在一个Bytebuf 里面,到最后再来解码成String,然后处理完了再把修改后的String写到hookContent里传递下去

@Rekoe
Copy link

Rekoe commented Dec 24, 2017

ok @monkeyWie 谢谢 按照你的思路 搞定了

@monkeyWie
Copy link
Owner

monkeyWie commented Dec 24, 2017

@Rekoe 这里要稍微注意下

String contentStr = contentBuf.toString(Charset.defaultCharset());

字符串编码的问题,最好是根据response里的content-type的charset来进行对应的解码,否则会导致乱码的
比如这个是utf-8的,可能还有gbk的就需要用gbk去解码
image

@tensorZhang
Copy link
Author

tensorZhang commented Dec 24, 2017

@monkeyWie 你好,“缓存一个ByteBuf在Intercept里,然后每次有HttpContent进来都写进缓存里,在LastHttpContent 时候就可以解码拿到所有的content了。”
这种方法,感觉也是将body体都放在了内存中。这种方法与使用HttpObjectAggregator得到FullHttpResponse,FullHttpRequest有什么区别呢,内存占用会有不同吗?麻烦解释下,谢谢!

@Rekoe
Copy link

Rekoe commented Dec 24, 2017

@tensorZhang 这个是处理代理 那个通道响应的数据的 不是Client的请求数据

@tensorZhang
Copy link
Author

tensorZhang commented Dec 25, 2017

@Rekoe 我现在是做一个监控请求与响应数据的工具。类似charles的工具,获取到请求响应数据后能进行一些数据解析,再展示。因为使用场景没有文件上传下载,我现在使用HttpObjectAggregator得到FullHttpResponse,FullHttpRequest的方案来实现。

@monkeyWie
Copy link
Owner

@tensorZhang 如果都用HttpObjectAggregator的话,响应体太大会全部加载在内存里,而HttpContent的方式就类似流,当你自己觉得业务数据能直接加载到内存里的时候,比如html,js,css这种文本文件,就可以自己来做缓存处理,比如下载的时候可能几个G的文件如果框架是用的HttpObjectAggregator来处理,就直接内存溢出了,所以还是开放给框架的使用者来处理。

你做抓包程序,比如遇到响应体大的可以缓存在硬盘里要查看的时候再从硬盘读取或者干脆不管,比如fiddler当响应体过大就直接不显示了。

@Rekoe
Copy link

Rekoe commented Dec 25, 2017

@tensorZhang 是的 我也是在扩展 Charles的请求 保存数据的功能

@tensorZhang
Copy link
Author

@monkeyWie 多谢
@Rekoe Charles项目有开源吗?git库能不能发一下

@Rekoe
Copy link

Rekoe commented Dec 25, 2017

@tensorZhang Charles 收费的

@tensorZhang
Copy link
Author

@Rekoe 好的,谢谢!

@litangyu
Copy link

litangyu commented Dec 26, 2017

fiddler 老版本网上有源码, 给你推荐一个开源的MITM中间人 https://github.com/mitmproxy/mitmproxy @tensorZhang

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

No branches or pull requests

4 participants