Comments (18)
@Rekoe 嗯嗯,有问题可以随时交流~
from proxyee.
@tensorZhang HttpProxyIntercept 这个类的方法就是解决你的需求的实现
from proxyee.
@Rekoe 多谢!我是这样拦截响应content的。用httpContent.copy();使response能够继续返回给客户端。不知这种用法是否优雅?
from proxyee.
@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的特殊处理
from proxyee.
@monkeyWie 好的 谢谢 就是想要这个这样的效果 我先参照看看
@tensorZhang 你那种方式会有问题 你看我#9里面的那个问题,问题就是那个结果
from proxyee.
@monkeyWie 刚看了下 ResponseTextIntercept
中的 public void afterResponse(Channel clientChannel, Channel proxyChannel, HttpContent httpContent, HttpProxyInterceptPipeline pipeline) throws Exception {....}
代码 这个是把多次的响应数据收集到一个bytebuf 中 最后通过 DefaultLastHttpContent
响应出去的么
from proxyee.
@Rekoe 是的,把所有的content缓存在一个Bytebuf 里面,到最后再来解码成String,然后处理完了再把修改后的String写到hookContent里传递下去
from proxyee.
ok @monkeyWie 谢谢 按照你的思路 搞定了
from proxyee.
@Rekoe 这里要稍微注意下
String contentStr = contentBuf.toString(Charset.defaultCharset());
字符串编码的问题,最好是根据response里的content-type的charset来进行对应的解码,否则会导致乱码的
比如这个是utf-8的,可能还有gbk的就需要用gbk去解码
from proxyee.
@monkeyWie 你好,“缓存一个ByteBuf在Intercept里,然后每次有HttpContent进来都写进缓存里,在LastHttpContent 时候就可以解码拿到所有的content了。”
这种方法,感觉也是将body体都放在了内存中。这种方法与使用HttpObjectAggregator得到FullHttpResponse,FullHttpRequest有什么区别呢,内存占用会有不同吗?麻烦解释下,谢谢!
from proxyee.
@tensorZhang 这个是处理代理 那个通道响应的数据的 不是Client的请求数据
from proxyee.
@Rekoe 我现在是做一个监控请求与响应数据的工具。类似charles的工具,获取到请求响应数据后能进行一些数据解析,再展示。因为使用场景没有文件上传下载,我现在使用HttpObjectAggregator得到FullHttpResponse,FullHttpRequest的方案来实现。
from proxyee.
@tensorZhang 如果都用HttpObjectAggregator的话,响应体太大会全部加载在内存里,而HttpContent的方式就类似流,当你自己觉得业务数据能直接加载到内存里的时候,比如html,js,css这种文本文件,就可以自己来做缓存处理,比如下载的时候可能几个G的文件如果框架是用的HttpObjectAggregator来处理,就直接内存溢出了,所以还是开放给框架的使用者来处理。
你做抓包程序,比如遇到响应体大的可以缓存在硬盘里要查看的时候再从硬盘读取或者干脆不管,比如fiddler当响应体过大就直接不显示了。
from proxyee.
@tensorZhang 是的 我也是在扩展 Charles的请求 保存数据的功能
from proxyee.
@monkeyWie 多谢
@Rekoe Charles项目有开源吗?git库能不能发一下
from proxyee.
@tensorZhang Charles 收费的
from proxyee.
@Rekoe 好的,谢谢!
from proxyee.
fiddler 老版本网上有源码, 给你推荐一个开源的MITM中间人 https://github.com/mitmproxy/mitmproxy @tensorZhang
from proxyee.
Related Issues (20)
- 您好,我想问下 我把这工程集成到springboot中,代理就不能正常工作了 HOT 3
- 抓不了JD的包
- 是否提供健康检查的方法? HOT 2
- TCP 链接数量一致在增加 HOT 6
- 请问开启了https代理后,某些网址,如gihtub.com不希望被代理如何设置 HOT 7
- 在阿里云申请了一个免费能信任的证书,替换了ca.crt和der,请问这个时候中间人做代理的时候,理论上会被信任吗 HOT 3
- 连接建立一段时间后,会稳定出现HTTP2超时异常 HOT 3
- Can I specify multiple outgoing ip addresses when I have multiple ethernet cards? HOT 1
- 证书错误,io.netty.handler.codec.DecoderException: javax.net.ssl.SSLHandshakeException: Read error: HOT 11
- How to send all the request generating from my application to the proxy HOT 1
- 请问开启了中间人代理后,代理流式(会持续返回)接口,如何实现也流式(response输出)返回,而不是等到最后响应结束后才一次过返回一堆结果(如json) HOT 8
- 大佬,支付宝APP抓不了包,报未知证书错误,但是其他APP可以,这是为啥呀 || Big Brother, the Alipay APP cannot capture the package, and reports an unknown certificate error, but other APPs can, why is this? HOT 1
- 多个拦截器 若某个拦截器的match方法若匹配一次 后续不匹配还会执行此拦截器的handleResponse方法 || Multiple interceptors If the match method of an interceptor matches once, the handleResponse method of this interceptor will be executed if there is no subsequent match
- java.lang.NullPointerException HOT 2
- proxyee设置支持ssl,运行时会出现 Received fatal alert: bad_certificate HOT 1
- 127.0.0.1:9999: invalid IPv6 address
- 支持一下socks5 || Support socks5 HOT 2
- ByteBuf.release() was not called before it's garbage-collected HOT 1
- Hi team, request help for accessing proxyee. HOT 5
- 是否有支持tcp的计划 || Is there any plan to support tcp?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proxyee.