anyproxy的安装与使用

anyproxy -i -r fxweb.js > test.log

 

启动语句比平时多了一句,both "-i(--intercept)" and rule.beforeDealHttpsRequest are specified, the "-i" option will be ignored,这句话的意思就是如果rule规则文件中定义了beforeDealHttpsRequest函数, 那么是否代理https将完全由这个函数的返回来决定;如果没有定义这个函数,那么是否代理https就由启动anyproxy时是否传入i参数来决定;所以说这第一个anyproxy实例其实是不能代理https的。那么这里要开的第二个anyproxy实例的rule规则文件可以修改为注释掉beforeDealHttpsRequest函数,

 

其中fxweb.js内容如下:

var logMap = {}
var fs = require('fs');
var logger = fs.createWriteStream(__dirname + '/urlLog.log', {
  flags: 'a' // 'a' means appending (old data will be preserved)
})
function logPageFile(url) {
    if (!logMap[url]) {
        logMap[url] = true;
        logger.write(url + '\r\n');
    }
}
module.exports = {
  // 模块介绍
  summary: 'my customized rule for AnyProxy',
  // 发送请求前拦截处理
  *beforeSendRequest(requestDetail) {  
        if( requestDetail.url.indexOf(".mp4?token=") != -1 ){
            logPageFile(requestDetail.url)
        }
    },
  // 发送响应前处理
  *beforeSendResponse(requestDetail, responseDetail) { /* ... */ },
  // 是否处理https请求
  *beforeDealHttpsRequest(requestDetail) { /* ... */ },
  // 请求出错的事件
  *onError(requestDetail, error) { /* ... */ },
  // https连接服务器出错
  *onConnectError(requestDetail, error) { /* ... */ }
};

 

posted @ 2021-10-27 14:53  lingwang3  阅读(210)  评论(0编辑  收藏  举报