proxyee
proxyee copied to clipboard
大佬,very 666
能设置用户名和密码就好了
你是说代理服务器的身份验证支持吗
是啊,就是使用代理的时候需要用户和密码,还问一下大佬,流量统计要咋做啊?
流量统计要做的话,得计算出请求和响应的报文大小,用一个拦截器应该可以实现
厉害啊,我写个流量统计的 `public class HttpProxyFlowHandle extends ChannelTrafficShapingHandler {
String clientIP;
Long lastWrittenBytes;
Long lastReadBytes;
public HttpProxyFlowHandle(long writeLimit, long readLimit, long checkInterval, long maxTime) {
super(writeLimit, readLimit, checkInterval, maxTime);
}
@Override
protected void doAccounting(TrafficCounter counter) {
lastWrittenBytes = counter.lastWrittenBytes();
lastReadBytes = counter.lastReadBytes();
BigDecimal b = new BigDecimal(lastWrittenBytes / 1024D / 1024D);
Double d = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
System.out.println(clientIP + ":上个监控周期读取了"+lastReadBytes+"个字节,发送了"+lastWrittenBytes+"个字节"+". 累计: "+d+"M");
super.doAccounting(counter);
}
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
InetSocketAddress insocket = (InetSocketAddress) ctx.channel().remoteAddress();
this.clientIP = insocket.getAddress().getHostAddress();
super.handlerAdded(ctx);
}
}`
ch.pipeline().addLast("flow", new HttpProxyFlowHandle(1000,100,8000L, 1000L*10));
用户名和密码就不知道咋弄了
用户名和密码的我有空的时候加下吧,不麻烦
我加了一个handle,用来验证用户名和密码,就是从request里面header获取验证信息 `public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if(msg instanceof HttpRequest){
HttpRequest request = (HttpRequest)msg;
HttpHeaders headers = request.headers();
log.info("{}", headers.toString());
}
ctx.fireChannelRead(msg);
}`
这里面的header只有几个很少的字段,header里面的cookies,conten-type等等其他的没有 大佬
代理服务器验证是有标准支持的,需要实现下这个标准
我改了一下,就是在返回的时候加上了:
httpResponse.setStatus(HttpResponseStatus.UNAUTHORIZED); httpResponse.headers().add("WWW-authenticate","Basic realm=\"\"");
在根据IP和用户名进行判断 代码被我改的有点乱,可以提交吗 ^_^
可以提交pr我看下
能独立成模块吗,如果能独立成模块的话就不用强塞到核心代码中了,方便维护。
提交pr了,写了独立模块