Git Product home page Git Product logo

Comments (18)

monkeyWie avatar monkeyWie commented on May 21, 2024 1

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

from proxyee.

Rekoe avatar Rekoe commented on May 21, 2024

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

from proxyee.

tensorZhang avatar tensorZhang commented on May 21, 2024

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

from proxyee.

monkeyWie avatar monkeyWie commented on May 21, 2024

@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.

Rekoe avatar Rekoe commented on May 21, 2024

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

from proxyee.

Rekoe avatar Rekoe commented on May 21, 2024

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

from proxyee.

monkeyWie avatar monkeyWie commented on May 21, 2024

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

from proxyee.

Rekoe avatar Rekoe commented on May 21, 2024

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

from proxyee.

monkeyWie avatar monkeyWie commented on May 21, 2024

@Rekoe 这里要稍微注意下

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

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

from proxyee.

tensorZhang avatar tensorZhang commented on May 21, 2024

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

from proxyee.

Rekoe avatar Rekoe commented on May 21, 2024

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

from proxyee.

tensorZhang avatar tensorZhang commented on May 21, 2024

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

from proxyee.

monkeyWie avatar monkeyWie commented on May 21, 2024

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

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

from proxyee.

Rekoe avatar Rekoe commented on May 21, 2024

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

from proxyee.

tensorZhang avatar tensorZhang commented on May 21, 2024

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

from proxyee.

Rekoe avatar Rekoe commented on May 21, 2024

@tensorZhang Charles 收费的

from proxyee.

tensorZhang avatar tensorZhang commented on May 21, 2024

@Rekoe 好的,谢谢!

from proxyee.

litangyu avatar litangyu commented on May 21, 2024

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

from proxyee.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.