Open zzmgc4 opened 1 year ago
不要使用FullResponseIntercept就行了,因为要完整解码响应的话肯定是得拿到全部的报文才行。
Just don't use FullResponseIntercept, because if you want to fully decode the response, you must get all the packets.
因为需要拿到请求的报文和响应的报文做内容审查,但是又不对原来的响应速度造成影响,可以一边先流式输出,等到结束才拿到所有报文存起来麽
理论上是可以的,但是需要自己实现一个类似FullResponseIntercept的拦截器,不过如果只是做记录的话很简单的,把每次过来的Content缓存住,判断是最后一个Content的时候再解码处理
pipeline.addLast(new 类似FullResponseIntercept的拦截器() { public boolean match(HttpRequest httpRequest, HttpResponse httpResponse, HttpProxyInterceptPipeline pipeline) { return true; } });
如果是这样下面这段还需要吗 public void afterResponse(Channel clientChannel, Channel proxyChannel, HttpResponse httpResponse, HttpProxyInterceptPipeline pipeline) throws Exception { this.fullHttpRequest.release(); FullHttpResponse fullHttpResponse = (FullHttpResponse) httpResponse; //保存数据库 save(); pipeline.afterResponse(clientChannel, proxyChannel, httpResponse); }
实现这个最基础的拦截器HttpProxyIntercept
里的这个方法就行了:
public void afterResponse(Channel clientChannel, Channel proxyChannel, HttpContent httpContent,
HttpProxyInterceptPipeline pipeline)
Just implement this method in the most basic interceptor HttpProxyIntercept
:
public void afterResponse(Channel clientChannel, Channel proxyChannel, HttpContent httpContent,
HttpProxyInterceptPipeline pipeline)
感谢大佬,我试试
Thanks guys, I'll try
是这个意思嘛
public abstract class AsynFullResponseIntercept extends HttpProxyIntercept {
private List
public void afterResponse(Channel clientChannel, Channel proxyChannel, HttpContent httpContent,
HttpProxyInterceptPipeline pipeline) throws Exception {
contentList.add(httpContent);
if (httpContent instanceof LastHttpContent) {
processContents(contentList);
contentList.clear();
}
// Continue with the pipeline
pipeline.afterResponse(clientChannel, proxyChannel, httpContent);
}
//say hello
private void processContents(List<HttpContent> contents) {
StringBuilder stringBuilder = new StringBuilder();
for (HttpContent content : contents) {
ByteBuf byteBuf = content.content();
stringBuilder.append(byteBuf.toString(CharsetUtil.UTF_8));
}
String result = stringBuilder.toString();
}
嗯,就是这个意思,然后细节方面你再调下应该就行了
Well, that’s what it means, and then you should adjust the details
{“result”:"1"} {“result”:"12"} {“result”:"123"}