ResponseTextIntercept.java 文件源码

java
阅读 22 收藏 0 点赞 0 评论 0

项目:proxyee-down 作者:
@Override
public void afterResponse(Channel clientChannel, Channel proxyChannel, HttpResponse httpResponse,
    HttpProxyInterceptPipeline pipeline) throws Exception {
  if (match(httpResponse, pipeline)) {
    isMatch = true;
    //解压gzip响应
    if ("gzip".equalsIgnoreCase(httpResponse.headers().get(HttpHeaderNames.CONTENT_ENCODING))) {
      isGzip = true;
      pipeline.reset3();
      proxyChannel.pipeline().addAfter("httpCodec", "decompress", new HttpContentDecompressor());
      proxyChannel.pipeline().fireChannelRead(httpResponse);
    } else {
      if (isGzip) {
        httpResponse.headers().set(HttpHeaderNames.CONTENT_ENCODING, HttpHeaderValues.GZIP);
      }
      contentBuf = PooledByteBufAllocator.DEFAULT.buffer();
      /*contentBuf.writeBytes(hookResponse().getBytes());
      for (HttpProxyIntercept intercept : pipeline) {
        if (intercept != this && intercept instanceof ResponseTextIntercept) {
          ResponseTextIntercept textIntercept = (ResponseTextIntercept) intercept;
          if (textIntercept.match(httpResponse, pipeline)) {
            contentBuf.writeBytes(textIntercept.hookResponse().getBytes());
          }
        }
      }*/
    }
    //直接调用默认拦截器,跳过下载拦截器
    pipeline.getDefault()
        .afterResponse(clientChannel, proxyChannel, httpResponse, pipeline);
  } else {
    isMatch = false;
    pipeline.afterResponse(clientChannel, proxyChannel, httpResponse);
  }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号