anyproxy 请问支持上游代理嘛

vxqlmq5t  于 2023-03-19  发布在  其他
关注(0)|答案(7)|浏览(198)

让anyproxy把请求发送个另一个http代理

ma8fv8wu

ma8fv8wu1#

#266 貌似说的是一个问题

2ledvvac

2ledvvac2#

Hi @yifeikong
明白你的意思了,可否介绍一下这种情形的使用场景, 就是类似于另一个代理是必须要经过的,但是同时也用AnyProxy来对这个请求和返回做处理吗?

ocebsuys

ocebsuys3#

某些公司的办公室内网必须通过代理服务才能访问外网

gpnt7bae

gpnt7bae4#

Hi @yifeikong@gucong3000
AnyProxy目前没有原生支持上游代理,如果你们是要自己使用,利用现在的Rule模块,也可以尝试。 因为在 rule的beforeSendRequest 方法中,已经将整个requestdetail对象透出,理论上上可以直接修改请求属性,将请求主机改为代理机器, 伪代码如下:

*beforeSendRequest(requestDetail) {
 const requestOption = requestDetail.requestOption;
 requestOption.hostname = '代理机器地址';
 requestOption.port = '代理机器端口';
 requestOption.path = '完整的url';
}

return requestDetail;
khbbv19g

khbbv19g5#

@codingfishman 我用这段代码能达到这个效果。
现在有另外个问题,我设置的是不解析https,这样的话https请求是不会进入beforeSendRequest的。
等于https请求也不会转发到上游代理,期望在不解析https的情况下也有办法转发https请求。

btqmn9zl

btqmn9zl6#

@biuuu
AnyProxy转发请求是基于能改变它的前提下,如果对https不开启代理,那么将无法再次转发。 能否问一下为何期望不解析https?

nhhxz33t

nhhxz33t7#

@codingfishman
如果我在客户端程序中直接使用上游代理( 同样是 http 代理),访问 https 网址不存在证书信任问题:

import requests
proxies = {'https': 'http://127.0.0.1:21343'}
resp = requests.get('https://httpbin.org/ip', proxies=proxies)
print(resp.text)

虽然代理服务器无法修改内容,但是很多场合下无需修改内容,仅仅是要一个转发。

如果经过 anyproxy 转发设置上游代理,将出现 CERTIFICATE_VERIFY_FAILED 的证书信任问题,rules 规则是这样的:

const httpProxyAgent = require('http-proxy-agent');
const httpsProxyAgent = require('https-proxy-agent');
module.exports = {
  // 模块介绍
  summary: 'my customized rule for AnyProxy',
  // 发送请求前拦截处理
  *beforeSendRequest(requestDetail) {
      const newRequestOptions = requestDetail.requestOptions;
      var agent = null;
      if(requestDetail.protocol == 'http') {
          agent = new httpProxyAgent("http://127.0.0.1:21343");
      } else {
          agent = new httpsProxyAgent("http://127.0.0.1:21343");
      }
      newRequestOptions.agent = agent;
      return {
        requestOptions: newRequestOptions
      };
  },
  *beforeDealHttpsRequest(requestDetail) {
    return true;
  }
};

Python 客户端程序使用 Anyproxy 的端口将报错:

Traceback (most recent call last):
  File "Untitled 3.py", line 3, in <module>
    resp = requests.get('https://httpbin.org/ip', proxies=proxies)
  File "/Library/Python/2.7/site-packages/requests-2.18.4-py2.7.egg/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/Library/Python/2.7/site-packages/requests-2.18.4-py2.7.egg/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Library/Python/2.7/site-packages/requests-2.18.4-py2.7.egg/requests/sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/Library/Python/2.7/site-packages/requests-2.18.4-py2.7.egg/requests/sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "/Library/Python/2.7/site-packages/requests-2.18.4-py2.7.egg/requests/adapters.py", line 506, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='httpbin.org', port=443): Max retries exceeded with url: /ip (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)'),))

请问:能否修改 options 的 agent 属性,同时不解析它的具体内容?
是否这种情况下我就不该再使用 anyproxy?

相关问题