Comments (5)
这个bug是什么情况才会出现呢,看起来是栈内存溢出了,估计是有无限递归的情况
from proxyee.
使用方法如下:
new Thread(new Runnable() {
@OverRide
public void run() {
new HttpProxyServer()
.proxyInterceptInitializer(new HttpProxyInterceptInitializer() {
@OverRide
public void init(HttpProxyInterceptPipeline pipeline) {
pipeline.addLast(new CertDownIntercept());
pipeline.addLast(new HttpProxyIntercept() {
@OverRide
public void beforeRequest(Channel clientChannel, HttpRequest httpRequest,
HttpProxyInterceptPipeline pipeline) throws Exception {
AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1");
//转到下一个拦截器处理
//----以下是截取uri提取部分,和代理无关
map.put(clientChannel.id().asShortText(),httpRequest.uri());
if(lt.size()>0){
for (int i = 0; i <lt.size() ; i++) {
String tm= httpRequest.uri();
String ta=lt.get(i).getValue();
if(ta.contains("(")&&ta.contains(")")){
int t1=ta.indexOf("(");
int t2=ta.lastIndexOf(")");
String tb=ta.substring(t1,t2+1);
String re11=ta.replace(tb,"tmppmt112233qq");
ta= re11.replace(".","\.").replace("?","\?").replace("+","\+");
tb=tb.substring(1,t2-t1);
ta= ta.replace("tmppmt112233qq",tb);
}else {
ta=ta.replace(".","\\.").replace("?","\\?").replace("+","\\+");
}
//----以上是截取uri提取部分,和代理无关
if(httpRequest.uri().matches(ta)){
String html = "<html><body>intercept</body><html>";
HttpResponse hookResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1,HttpResponseStatus.OK);
hookResponse.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html");
hookResponse.headers().set(HttpHeaderNames.CONTENT_LENGTH, html.getBytes().length);
pipeline.getDefault().afterResponse(clientChannel, null , hookResponse, pipeline);
HttpContent hookContent = new DefaultLastHttpContent();
hookContent.content().writeBytes(html.getBytes());
pipeline.getDefault().afterResponse(clientChannel, null, hookContent, pipeline);
}else {
pipeline.beforeRequest(clientChannel, httpRequest);
}
}
}
}
@Override
public void afterResponse(Channel clientChannel, Channel proxyChannel,
HttpResponse httpResponse,
HttpProxyInterceptPipeline pipeline) throws Exception {
//拦截响应,添加一个响应头
//httpResponse.headers().add("intercept", "test");
if(map.containsKey(proxyChannel.id().asShortText())){
map.remove(proxyChannel.id().asShortText());
}
pipeline.afterResponse(clientChannel, proxyChannel, httpResponse);
}
});
}
}).start(8102);
}
}).start();
}
from proxyee.
你是在for循环里调用了pipeline.beforeRequest(clientChannel, httpRequest)吗,这个是处理完逻辑之后再调用,使用下一个handler来处理的
from proxyee.
不经过服务器,直接本地拦截可以写的更简单点
pipeline.addLast(new HttpProxyIntercept() {
@Override
public void beforeRequest(Channel clientChannel, HttpRequest httpRequest,
HttpProxyInterceptPipeline pipeline) throws Exception {
if (httpRequest.uri().equals("/test.html")) { //匹配的uri直接返回response
String html = "<html><body>intercept</body><html>";
HttpResponse hookResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1,HttpResponseStatus.OK);
hookResponse.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html");
hookResponse.headers().set(HttpHeaderNames.CONTENT_LENGTH, html.getBytes().length);
//直接输出http响应体至客户端,不走后面的转发handler了
clientChannel.writeAndFlush(hookResponse);
HttpContent hookContent = new DefaultLastHttpContent();
hookContent.content().writeBytes(html.getBytes());
clientChannel.writeAndFlush(hookContent );
}else{
pipeline.beforeRequest(clientChannel, httpRequest);
}
}
});
from proxyee.
成功啦,谢谢大神了,果然多次handle 了
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.