proxyee icon indicating copy to clipboard operation
proxyee copied to clipboard

大佬,very 666

Open liming1010 opened this issue 5 years ago • 11 comments

能设置用户名和密码就好了

liming1010 avatar Oct 27 '20 01:10 liming1010

你是说代理服务器的身份验证支持吗

monkeyWie avatar Oct 27 '20 01:10 monkeyWie

是啊,就是使用代理的时候需要用户和密码,还问一下大佬,流量统计要咋做啊?

liming1010 avatar Oct 27 '20 06:10 liming1010

流量统计要做的话,得计算出请求和响应的报文大小,用一个拦截器应该可以实现

monkeyWie avatar Oct 27 '20 09:10 monkeyWie

厉害啊,我写个流量统计的 `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));

用户名和密码就不知道咋弄了

liming1010 avatar Oct 27 '20 09:10 liming1010

用户名和密码的我有空的时候加下吧,不麻烦

monkeyWie avatar Oct 27 '20 09:10 monkeyWie

我加了一个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等等其他的没有 大佬

liming1010 avatar Oct 28 '20 07:10 liming1010

代理服务器验证是有标准支持的,需要实现下这个标准

monkeyWie avatar Oct 29 '20 03:10 monkeyWie

我改了一下,就是在返回的时候加上了: httpResponse.setStatus(HttpResponseStatus.UNAUTHORIZED); httpResponse.headers().add("WWW-authenticate","Basic realm=\"\"");

在根据IP和用户名进行判断 代码被我改的有点乱,可以提交吗 ^_^

liming1010 avatar Oct 30 '20 08:10 liming1010

可以提交pr我看下

monkeyWie avatar Oct 30 '20 08:10 monkeyWie

能独立成模块吗,如果能独立成模块的话就不用强塞到核心代码中了,方便维护。

LamGC avatar Nov 01 '20 13:11 LamGC

提交pr了,写了独立模块

liming1010 avatar Nov 02 '20 06:11 liming1010