mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-04-23 16:01:26 +00:00
update faq
This commit is contained in:
parent
8bc5aa1b72
commit
c4e6aeb3e7
66
cn.html
66
cn.html
@ -74,6 +74,8 @@
|
|||||||
<li class="sidebar-header-3"><a href="#ios系统信任ca证书">iOS系统信任CA证书</a></li>
|
<li class="sidebar-header-3"><a href="#ios系统信任ca证书">iOS系统信任CA证书</a></li>
|
||||||
<li class="sidebar-header-3"><a href="#ios->=-10.3信任ca证书">iOS >= 10.3信任CA证书</a></li>
|
<li class="sidebar-header-3"><a href="#ios->=-10.3信任ca证书">iOS >= 10.3信任CA证书</a></li>
|
||||||
<li class="sidebar-header-3"><a href="#配置ios/android系统代理">配置iOS/Android系统代理</a></li>
|
<li class="sidebar-header-3"><a href="#配置ios/android系统代理">配置iOS/Android系统代理</a></li>
|
||||||
|
<li class="sidebar-header-2"><a href="#faq-1">FAQ</a></li>
|
||||||
|
<li class="sidebar-header-3"><a href="#the-connection-is-not-private">The connection is not private</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -99,6 +101,8 @@
|
|||||||
<p class="img-container"><img src="https://zos.alipayobjects.com/rmsportal/SqVntpzmscXPbSzfcGcr.png" width="500" /></p>
|
<p class="img-container"><img src="https://zos.alipayobjects.com/rmsportal/SqVntpzmscXPbSzfcGcr.png" width="500" /></p>
|
||||||
<h2 id="快速上手"><a class="header-link" href="#快速上手"></a>快速上手</h2>
|
<h2 id="快速上手"><a class="header-link" href="#快速上手"></a>快速上手</h2>
|
||||||
<h3 id="安装"><a class="header-link" href="#安装"></a>安装</h3>
|
<h3 id="安装"><a class="header-link" href="#安装"></a>安装</h3>
|
||||||
|
<p>对于Debian或者Ubuntu系统,在安装AnyProxy之前,可能还需要安装 <code>nodejs-legacy</code></p>
|
||||||
|
<pre class="hljs"><code>sudo apg-get install nodejs-legacy</code></pre><p>然后,安装AnyProxy</p>
|
||||||
<pre class="hljs"><code>npm install -g anyproxy@beta <span class="hljs-comment">#本文档对应的AnyProxy为4.0Beta版</span></code></pre><h3 id="启动"><a class="header-link" href="#启动"></a>启动</h3>
|
<pre class="hljs"><code>npm install -g anyproxy@beta <span class="hljs-comment">#本文档对应的AnyProxy为4.0Beta版</span></code></pre><h3 id="启动"><a class="header-link" href="#启动"></a>启动</h3>
|
||||||
<ul class="list">
|
<ul class="list">
|
||||||
<li>命令行启动AnyProxy,默认端口号8001</li>
|
<li>命令行启动AnyProxy,默认端口号8001</li>
|
||||||
@ -175,9 +179,9 @@ anyproxy --intercept <span class="hljs-comment">#启动AnyProxy,并解析所
|
|||||||
</li>
|
</li>
|
||||||
<li><p>Step 3, 测试规则</p>
|
<li><p>Step 3, 测试规则</p>
|
||||||
<ul class="list">
|
<ul class="list">
|
||||||
<li><p>用curl测试 </p>
|
<li><p>用curl测试</p>
|
||||||
<pre class="hljs"><code>curl http://httpbin.org/user-agent --proxy http://127.0.0.1:8001</code></pre></li>
|
<pre class="hljs"><code>curl http://httpbin.org/user-agent --proxy http://127.0.0.1:8001</code></pre></li>
|
||||||
<li><p>用浏览器测试:配置浏览器http代理为 127.0.0.1:8001,访问 <a href="http://httpbin.org/user-agent">http://httpbin.org/user-agent</a> </p>
|
<li><p>用浏览器测试:配置浏览器http代理为 127.0.0.1:8001,访问 <a href="http://httpbin.org/user-agent">http://httpbin.org/user-agent</a></p>
|
||||||
</li>
|
</li>
|
||||||
<li><p>经过代理服务器后,期望的返回如下</p>
|
<li><p>经过代理服务器后,期望的返回如下</p>
|
||||||
</li>
|
</li>
|
||||||
@ -232,17 +236,17 @@ npm i -g myRulePkg && anyproxy --rule myRulePkg <span class="hljs-commen
|
|||||||
<p>规则模块应该符合cmd规范,一个典型的规则模块代码结构如下。模块中所有方法都是可选的,只需实现业务感兴趣的部分即可。</p>
|
<p>规则模块应该符合cmd规范,一个典型的规则模块代码结构如下。模块中所有方法都是可选的,只需实现业务感兴趣的部分即可。</p>
|
||||||
<pre class="hljs"><code><span class="hljs-built_in">module</span>.exports = {
|
<pre class="hljs"><code><span class="hljs-built_in">module</span>.exports = {
|
||||||
<span class="hljs-comment">// 模块介绍</span>
|
<span class="hljs-comment">// 模块介绍</span>
|
||||||
summary: <span class="hljs-string">'my customized rule for AnyProxy'</span>,
|
summary: <span class="hljs-string">'my customized rule for AnyProxy'</span>,
|
||||||
<span class="hljs-comment">// 发送请求前拦截处理</span>
|
<span class="hljs-comment">// 发送请求前拦截处理</span>
|
||||||
*beforeSendRequest(requestDetail) { <span class="hljs-comment">/* ... */</span> },
|
*beforeSendRequest(requestDetail) { <span class="hljs-comment">/* ... */</span> },
|
||||||
<span class="hljs-comment">// 发送响应前处理</span>
|
<span class="hljs-comment">// 发送响应前处理</span>
|
||||||
*beforeSendResponse(requestDetail, responseDetail) { <span class="hljs-comment">/* ... */</span> },
|
*beforeSendResponse(requestDetail, responseDetail) { <span class="hljs-comment">/* ... */</span> },
|
||||||
<span class="hljs-comment">// 是否处理https请求</span>
|
<span class="hljs-comment">// 是否处理https请求</span>
|
||||||
*beforeDealHttpsRequest(requestDetail) { <span class="hljs-comment">/* ... */</span> },
|
*beforeDealHttpsRequest(requestDetail) { <span class="hljs-comment">/* ... */</span> },
|
||||||
<span class="hljs-comment">// 请求出错的事件</span>
|
<span class="hljs-comment">// 请求出错的事件</span>
|
||||||
*onError(requestDetail, error) { <span class="hljs-comment">/* ... */</span> },
|
*onError(requestDetail, error) { <span class="hljs-comment">/* ... */</span> },
|
||||||
<span class="hljs-comment">// https连接服务器出错</span>
|
<span class="hljs-comment">// https连接服务器出错</span>
|
||||||
*onConnectError(requestDetail, error) { <span class="hljs-comment">/* ... */</span> }
|
*onConnectError(requestDetail, error) { <span class="hljs-comment">/* ... */</span> }
|
||||||
};</code></pre><blockquote>
|
};</code></pre><blockquote>
|
||||||
<p>规则文件中,除了summary,都是由 <a href="https://www.npmjs.com/package/co">co</a> 驱动的,函数需要满足yieldable。可以返回promise或使用generator函数。</p>
|
<p>规则文件中,除了summary,都是由 <a href="https://www.npmjs.com/package/co">co</a> 驱动的,函数需要满足yieldable。可以返回promise或使用generator函数。</p>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
@ -255,7 +259,7 @@ npm i -g myRulePkg && anyproxy --rule myRulePkg <span class="hljs-commen
|
|||||||
<h4 id="beforesendrequest(requestdetail)"><a class="header-link" href="#beforesendrequest(requestdetail)"></a>beforeSendRequest(requestDetail)</h4>
|
<h4 id="beforesendrequest(requestdetail)"><a class="header-link" href="#beforesendrequest(requestdetail)"></a>beforeSendRequest(requestDetail)</h4>
|
||||||
<ul class="list">
|
<ul class="list">
|
||||||
<li>AnyProxy向服务端发送请求前,会调用<code>beforeSendRequest</code>,并带上参数<code>requestDetail</code></li>
|
<li>AnyProxy向服务端发送请求前,会调用<code>beforeSendRequest</code>,并带上参数<code>requestDetail</code></li>
|
||||||
<li><code>requestDetail</code> <ul class="list">
|
<li><code>requestDetail</code><ul class="list">
|
||||||
<li><code>protocol</code> {string} 请求使用的协议,http或者https</li>
|
<li><code>protocol</code> {string} 请求使用的协议,http或者https</li>
|
||||||
<li><code>requestOptions</code> {object} 即将发送的请求配置,供require('http').request作为使用。详见:<a href="https://nodejs.org/api/http.html#http_http_request_options_callback">https://nodejs.org/api/http.html#http_http_request_options_callback</a></li>
|
<li><code>requestOptions</code> {object} 即将发送的请求配置,供require('http').request作为使用。详见:<a href="https://nodejs.org/api/http.html#http_http_request_options_callback">https://nodejs.org/api/http.html#http_http_request_options_callback</a></li>
|
||||||
<li><code>requestData</code> {object} 请求Body</li>
|
<li><code>requestData</code> {object} 请求Body</li>
|
||||||
@ -319,16 +323,16 @@ newOption.path = <span class="hljs-string">'/redirect/to/another/path'</span>;
|
|||||||
<ul class="list">
|
<ul class="list">
|
||||||
<li>AnyProxy向客户端发送请求前,会调用<code>beforeSendResponse</code>,并带上参数<code>requestDetail</code> <code>responseDetail</code></li>
|
<li>AnyProxy向客户端发送请求前,会调用<code>beforeSendResponse</code>,并带上参数<code>requestDetail</code> <code>responseDetail</code></li>
|
||||||
<li><code>requestDetail</code> 同<code>beforeSendRequest</code>中的参数</li>
|
<li><code>requestDetail</code> 同<code>beforeSendRequest</code>中的参数</li>
|
||||||
<li><code>responseDetail</code> <ul class="list">
|
<li><code>responseDetail</code><ul class="list">
|
||||||
<li><code>response</code> {object} 服务端的返回信息,包括<code>statusCode</code> <code>header</code> <code>body</code>三个字段</li>
|
<li><code>response</code> {object} 服务端的返回信息,包括<code>statusCode</code> <code>header</code> <code>body</code>三个字段</li>
|
||||||
<li><code>_res</code> {object} 原始的服务端返回对象</li>
|
<li><code>_res</code> {object} 原始的服务端返回对象</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li><p>举例,请求 <em>anyproxy.io</em> 时,<code>responseDetail</code>参数内容大致如下</p>
|
<li><p>举例,请求 <em>anyproxy.io</em> 时,<code>responseDetail</code>参数内容大致如下</p>
|
||||||
<pre class="hljs"><code>{
|
<pre class="hljs"><code>{
|
||||||
<span class="hljs-attr">response</span>: {
|
<span class="hljs-attr">response</span>: {
|
||||||
<span class="hljs-attr">statusCode</span>: <span class="hljs-number">200</span>,
|
<span class="hljs-attr">statusCode</span>: <span class="hljs-number">200</span>,
|
||||||
<span class="hljs-attr">header</span>: {
|
<span class="hljs-attr">header</span>: {
|
||||||
<span class="hljs-string">'Content-Type'</span>: <span class="hljs-string">'image/gif'</span>,
|
<span class="hljs-string">'Content-Type'</span>: <span class="hljs-string">'image/gif'</span>,
|
||||||
<span class="hljs-attr">Connection</span>: <span class="hljs-string">'close'</span>,
|
<span class="hljs-attr">Connection</span>: <span class="hljs-string">'close'</span>,
|
||||||
<span class="hljs-string">'Cache-Control'</span>: <span class="hljs-string">'...'</span>
|
<span class="hljs-string">'Cache-Control'</span>: <span class="hljs-string">'...'</span>
|
||||||
@ -687,7 +691,7 @@ proxyServer.close();</code></pre><ul class="list">
|
|||||||
<li>使用示例</li>
|
<li>使用示例</li>
|
||||||
</ul>
|
</ul>
|
||||||
<pre class="hljs"><code><span class="hljs-comment">// 配置127.0.0.1:8001为全局http代理服务器</span>
|
<pre class="hljs"><code><span class="hljs-comment">// 配置127.0.0.1:8001为全局http代理服务器</span>
|
||||||
AnyProxy.utils.systemProxyMgr.enableGlobalProxy(<span class="hljs-string">'127.0.0.1'</span>, <span class="hljs-string">'8001'</span>);
|
AnyProxy.utils.systemProxyMgr.enableGlobalProxy(<span class="hljs-string">'127.0.0.1'</span>, <span class="hljs-string">'8001'</span>);
|
||||||
|
|
||||||
<span class="hljs-comment">// 关闭全局代理服务器</span>
|
<span class="hljs-comment">// 关闭全局代理服务器</span>
|
||||||
AnyProxy.utils.systemProxyMgr.disableGlobalProxy();</code></pre></li>
|
AnyProxy.utils.systemProxyMgr.disableGlobalProxy();</code></pre></li>
|
||||||
@ -772,7 +776,7 @@ AnyProxy.utils.systemProxyMgr.disableGlobalProxy();</code></pre></li>
|
|||||||
<p class="img-container"><img src="https://zos.alipayobjects.com/rmsportal/BrugmMelGVysLDOIBblj.png" width="260" /></p>
|
<p class="img-container"><img src="https://zos.alipayobjects.com/rmsportal/BrugmMelGVysLDOIBblj.png" width="260" /></p>
|
||||||
<h3 id="ios->=-10.3信任ca证书"><a class="header-link" href="#ios->=-10.3信任ca证书"></a>iOS >= 10.3信任CA证书</h3>
|
<h3 id="ios->=-10.3信任ca证书"><a class="header-link" href="#ios->=-10.3信任ca证书"></a>iOS >= 10.3信任CA证书</h3>
|
||||||
<ul class="list">
|
<ul class="list">
|
||||||
<li>除了上述证书安装过程,还需要在 <em>设置->通用->证书信任设置</em> 中把AnyProxy证书的开关打开,否则safari将报错。</li>
|
<li>除了上述证书安装过程,还需要在 <em>设置->通用->关于本机->证书信任设置</em> 中把AnyProxy证书的开关打开,否则safari将报错。</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p class="img-container"><img src="https://zos.alipayobjects.com/rmsportal/hVWkXHrzHmOKOtCKGUWx.png" width="500" /></p>
|
<p class="img-container"><img src="https://zos.alipayobjects.com/rmsportal/hVWkXHrzHmOKOtCKGUWx.png" width="500" /></p>
|
||||||
<h3 id="配置ios/android系统代理"><a class="header-link" href="#配置ios/android系统代理"></a>配置iOS/Android系统代理</h3>
|
<h3 id="配置ios/android系统代理"><a class="header-link" href="#配置ios/android系统代理"></a>配置iOS/Android系统代理</h3>
|
||||||
@ -787,6 +791,38 @@ AnyProxy.utils.systemProxyMgr.disableGlobalProxy();</code></pre></li>
|
|||||||
<li>Android HTTP代理配置</li>
|
<li>Android HTTP代理配置</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p class="img-container"><img src="https://zos.alipayobjects.com/rmsportal/YQtbQYVNuOszZGdAOauU.png" width="260" /></p>
|
<p class="img-container"><img src="https://zos.alipayobjects.com/rmsportal/YQtbQYVNuOszZGdAOauU.png" width="260" /></p>
|
||||||
|
<h2 id="faq-1"><a class="header-link" href="#faq-1"></a>FAQ</h2>
|
||||||
|
<h3 id="the-connection-is-not-private"><a class="header-link" href="#the-connection-is-not-private"></a>The connection is not private</h3>
|
||||||
|
<p>访问特定的HTTPS站点时,AnyProxy会提示该站点不是一个安全的网站,这通常是因为站点的证书设置不能被正确信任(比如,<a href="https://github.com/nodejs/node/issues/4175">Nodejs不读取系统配置,需要手动传入ca</a>)。</p>
|
||||||
|
<p>在评估了安全风险后,可以用以下方式绕过证书校验:</p>
|
||||||
|
<ul class="list">
|
||||||
|
<li><p>命令行启动</p>
|
||||||
|
<p>通过启动参数 <code>--ignore-unauthorized-ssl</code> 来忽略<strong>所有的</strong>证书认证的错误。</p>
|
||||||
|
<pre class="hljs"><code>anyproxy -i --ignore-unauthorized-ssl</code></pre></li>
|
||||||
|
<li><p>作为npm模块启动 </p>
|
||||||
|
<p>在构造AnyProxy实例的时候,传入参数<code>dangerouslyIgnoreUnauthorized:true</code>, 如下:</p>
|
||||||
|
<pre class="hljs"><code> <span class="hljs-keyword">const</span> options = {
|
||||||
|
...,
|
||||||
|
<span class="hljs-attr">dangerouslyIgnoreUnauthorized</span>: <span class="hljs-literal">true</span> <span class="hljs-comment">// 请注意这个配置对AnyProxy所有请求都生效</span>
|
||||||
|
};
|
||||||
|
|
||||||
|
<span class="hljs-keyword">const</span> anyproxyIns = <span class="hljs-keyword">new</span> AnyProxy.ProxyCore(options);
|
||||||
|
anyproxyIns.start();</code></pre></li>
|
||||||
|
<li><p>通过自定义的Rule来修改 </p>
|
||||||
|
<p>我们自然也可以借助自定义的Rule来对特定请求配置<code>rejectUnauthorized</code>。</p>
|
||||||
|
<pre class="hljs"><code><span class="hljs-built_in">module</span>.exports = {
|
||||||
|
*beforeSendRequest(requestDetail) {
|
||||||
|
<span class="hljs-keyword">if</span> (requestDetail.url.indexOf(<span class="hljs-string">'https://the-site-you-know.com'</span>) === <span class="hljs-number">0</span>) {
|
||||||
|
<span class="hljs-keyword">const</span> newRequestOptions = requestDetail.requestOptions;
|
||||||
|
<span class="hljs-comment">// 设置属性 rejectUnauthorized 为 false</span>
|
||||||
|
newRequestOptions.rejectUnauthorized = <span class="hljs-literal">false</span>;
|
||||||
|
<span class="hljs-keyword">return</span> {
|
||||||
|
<span class="hljs-attr">requestOptions</span>: newRequestOptions
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};</code></pre></li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
|
72
en.html
72
en.html
@ -74,13 +74,15 @@
|
|||||||
<li class="sidebar-header-3"><a href="#trust-root-ca-in-ios">trust root CA in iOS</a></li>
|
<li class="sidebar-header-3"><a href="#trust-root-ca-in-ios">trust root CA in iOS</a></li>
|
||||||
<li class="sidebar-header-3"><a href="#trust-root-ca-in-ios->=-10.3">trust root CA in iOS >= 10.3</a></li>
|
<li class="sidebar-header-3"><a href="#trust-root-ca-in-ios->=-10.3">trust root CA in iOS >= 10.3</a></li>
|
||||||
<li class="sidebar-header-3"><a href="#config-ios/android-proxy-server">config iOS/Android proxy server</a></li>
|
<li class="sidebar-header-3"><a href="#config-ios/android-proxy-server">config iOS/Android proxy server</a></li>
|
||||||
|
<li class="sidebar-header-2"><a href="#faq-1">FAQ</a></li>
|
||||||
|
<li class="sidebar-header-3"><a href="#the-connection-is-not-private">The connection is not private</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="main-content"><h1 id="anyproxy"><a class="header-link" href="#anyproxy"></a>AnyProxy</h1>
|
<div class="main-content"><h1 id="anyproxy"><a class="header-link" href="#anyproxy"></a>AnyProxy</h1>
|
||||||
<p>AnyProxy is a fully configurable http/https proxy in NodeJS. Version 4.0 is in beta now.</p>
|
<p>AnyProxy is a fully configurable http/https proxy in NodeJS. Version 4.0 is in beta now.</p>
|
||||||
<p>Ref: <a href="./cn.html">Chinese Doc 中文文档</a></p>
|
<p>Ref: <a href="./cn.html">Chinese Doc 中文文档</a></p>
|
||||||
<p>Github: </p>
|
<p>Github:</p>
|
||||||
<ul class="list">
|
<ul class="list">
|
||||||
<li><a href="https://github.com/alibaba/anyproxy/tree/4.x">https://github.com/alibaba/anyproxy/tree/4.x</a></li>
|
<li><a href="https://github.com/alibaba/anyproxy/tree/4.x">https://github.com/alibaba/anyproxy/tree/4.x</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -99,6 +101,8 @@
|
|||||||
<p class="img-container"><img src="https://zos.alipayobjects.com/rmsportal/SqVntpzmscXPbSzfcGcr.png" width="500" /></p>
|
<p class="img-container"><img src="https://zos.alipayobjects.com/rmsportal/SqVntpzmscXPbSzfcGcr.png" width="500" /></p>
|
||||||
<h2 id="quick-start"><a class="header-link" href="#quick-start"></a>Quick start</h2>
|
<h2 id="quick-start"><a class="header-link" href="#quick-start"></a>Quick start</h2>
|
||||||
<h3 id="install"><a class="header-link" href="#install"></a>install</h3>
|
<h3 id="install"><a class="header-link" href="#install"></a>install</h3>
|
||||||
|
<p>To Debian and Ubuntu users, you may need to install <code>nodejs-legacy</code> at the same time</p>
|
||||||
|
<pre class="hljs"><code>sudo apg-get install nodejs-legacy</code></pre><p>Then install the AnyProxy</p>
|
||||||
<pre class="hljs"><code>npm install -g anyproxy@beta <span class="hljs-comment"># 4.x is in beta now</span></code></pre><h3 id="launch"><a class="header-link" href="#launch"></a>launch</h3>
|
<pre class="hljs"><code>npm install -g anyproxy@beta <span class="hljs-comment"># 4.x is in beta now</span></code></pre><h3 id="launch"><a class="header-link" href="#launch"></a>launch</h3>
|
||||||
<ul class="list">
|
<ul class="list">
|
||||||
<li>start AnyProxy in command line, with default port 8001</li>
|
<li>start AnyProxy in command line, with default port 8001</li>
|
||||||
@ -172,11 +176,11 @@ anyproxy --intercept <span class="hljs-comment">#launch anyproxy and intercept a
|
|||||||
</li>
|
</li>
|
||||||
<li><p>Step 3, test</p>
|
<li><p>Step 3, test</p>
|
||||||
<ul class="list">
|
<ul class="list">
|
||||||
<li><p>use curl </p>
|
<li><p>use curl</p>
|
||||||
<pre class="hljs"><code>curl http://httpbin.org/user-agent --proxy http://127.0.0.1:8001</code></pre></li>
|
<pre class="hljs"><code>curl http://httpbin.org/user-agent --proxy http://127.0.0.1:8001</code></pre></li>
|
||||||
<li><p>use browser. Point the http proxy of browser to 127.0.0.1:8001, then visit <a href="http://httpbin.org/user-agent">http://httpbin.org/user-agent</a> </p>
|
<li><p>use browser. Point the http proxy of browser to 127.0.0.1:8001, then visit <a href="http://httpbin.org/user-agent">http://httpbin.org/user-agent</a></p>
|
||||||
</li>
|
</li>
|
||||||
<li><p>the expected response from proxy is </p>
|
<li><p>the expected response from proxy is</p>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<pre class="hljs"><code>{
|
<pre class="hljs"><code>{
|
||||||
@ -229,17 +233,17 @@ npm i -g myRulePkg && anyproxy --rule myRulePkg <span class="hljs-commen
|
|||||||
<p>A typical rule module is as follows. All the functions are optional, just write the part you are interested in.</p>
|
<p>A typical rule module is as follows. All the functions are optional, just write the part you are interested in.</p>
|
||||||
<pre class="hljs"><code><span class="hljs-built_in">module</span>.exports = {
|
<pre class="hljs"><code><span class="hljs-built_in">module</span>.exports = {
|
||||||
<span class="hljs-comment">// introduction</span>
|
<span class="hljs-comment">// introduction</span>
|
||||||
summary: <span class="hljs-string">'my customized rule for AnyProxy'</span>,
|
summary: <span class="hljs-string">'my customized rule for AnyProxy'</span>,
|
||||||
<span class="hljs-comment">// intercept before send request to server</span>
|
<span class="hljs-comment">// intercept before send request to server</span>
|
||||||
*beforeSendRequest(requestDetail) { <span class="hljs-comment">/* ... */</span> },
|
*beforeSendRequest(requestDetail) { <span class="hljs-comment">/* ... */</span> },
|
||||||
<span class="hljs-comment">// deal response before send to client </span>
|
<span class="hljs-comment">// deal response before send to client</span>
|
||||||
*beforeSendResponse(requestDetail, responseDetail) { <span class="hljs-comment">/* ... */</span> },
|
*beforeSendResponse(requestDetail, responseDetail) { <span class="hljs-comment">/* ... */</span> },
|
||||||
<span class="hljs-comment">// if deal https request</span>
|
<span class="hljs-comment">// if deal https request</span>
|
||||||
*beforeDealHttpsRequest(requestDetail) { <span class="hljs-comment">/* ... */</span> },
|
*beforeDealHttpsRequest(requestDetail) { <span class="hljs-comment">/* ... */</span> },
|
||||||
<span class="hljs-comment">// error happened when dealing requests</span>
|
<span class="hljs-comment">// error happened when dealing requests</span>
|
||||||
*onError(requestDetail, error) { <span class="hljs-comment">/* ... */</span> },
|
*onError(requestDetail, error) { <span class="hljs-comment">/* ... */</span> },
|
||||||
<span class="hljs-comment">// error happened when connect to https server</span>
|
<span class="hljs-comment">// error happened when connect to https server</span>
|
||||||
*onConnectError(requestDetail, error) { <span class="hljs-comment">/* ... */</span> }
|
*onConnectError(requestDetail, error) { <span class="hljs-comment">/* ... */</span> }
|
||||||
};</code></pre><blockquote>
|
};</code></pre><blockquote>
|
||||||
<p>All functions in your rule file, except summary, are all driven by <a href="https://www.npmjs.com/package/co">co</a> . They should be yieldable, i.e. return a promise or be a generator function.</p>
|
<p>All functions in your rule file, except summary, are all driven by <a href="https://www.npmjs.com/package/co">co</a> . They should be yieldable, i.e. return a promise or be a generator function.</p>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
@ -252,7 +256,7 @@ npm i -g myRulePkg && anyproxy --rule myRulePkg <span class="hljs-commen
|
|||||||
<h4 id="beforesendrequest(requestdetail)"><a class="header-link" href="#beforesendrequest(requestdetail)"></a>beforeSendRequest(requestDetail)</h4>
|
<h4 id="beforesendrequest(requestdetail)"><a class="header-link" href="#beforesendrequest(requestdetail)"></a>beforeSendRequest(requestDetail)</h4>
|
||||||
<ul class="list">
|
<ul class="list">
|
||||||
<li>Before sending request to server, AnyProxy will call <code>beforeSendRequest</code> with param <code>requestDetail</code></li>
|
<li>Before sending request to server, AnyProxy will call <code>beforeSendRequest</code> with param <code>requestDetail</code></li>
|
||||||
<li><code>requestDetail</code> <ul class="list">
|
<li><code>requestDetail</code><ul class="list">
|
||||||
<li><code>protocol</code> {string} the protocol to use, http or https</li>
|
<li><code>protocol</code> {string} the protocol to use, http or https</li>
|
||||||
<li><code>requestOptions</code> {object} the options of the request-to-go, a param of require('http').request . ref: <a href="https://nodejs.org/api/http.html#http_http_request_options_callback">https://nodejs.org/api/http.html#http_http_request_options_callback</a></li>
|
<li><code>requestOptions</code> {object} the options of the request-to-go, a param of require('http').request . ref: <a href="https://nodejs.org/api/http.html#http_http_request_options_callback">https://nodejs.org/api/http.html#http_http_request_options_callback</a></li>
|
||||||
<li><code>requestData</code> {object} request body</li>
|
<li><code>requestData</code> {object} request body</li>
|
||||||
@ -316,16 +320,16 @@ newOption.path = <span class="hljs-string">'/redirect/to/another/path'</span>;
|
|||||||
<ul class="list">
|
<ul class="list">
|
||||||
<li>Before sending response to client, AnyProxy will call <code>beforeSendResponse</code> with param <code>requestDetail</code> <code>responseDetail</code></li>
|
<li>Before sending response to client, AnyProxy will call <code>beforeSendResponse</code> with param <code>requestDetail</code> <code>responseDetail</code></li>
|
||||||
<li><code>requestDetail</code> is the same param as in <code>beforeSendRequest</code></li>
|
<li><code>requestDetail</code> is the same param as in <code>beforeSendRequest</code></li>
|
||||||
<li><code>responseDetail</code> <ul class="list">
|
<li><code>responseDetail</code><ul class="list">
|
||||||
<li><code>response</code> {object} the response from server, includes <code>statusCode</code> <code>header</code> <code>body</code></li>
|
<li><code>response</code> {object} the response from server, includes <code>statusCode</code> <code>header</code> <code>body</code></li>
|
||||||
<li><code>_res</code> {object} the native node.js response object</li>
|
<li><code>_res</code> {object} the native node.js response object</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li><p>e.g. When requesting <em>anyproxy.io</em>, <code>responseDetail</code> is something like the following</p>
|
<li><p>e.g. When requesting <em>anyproxy.io</em>, <code>responseDetail</code> is something like the following</p>
|
||||||
<pre class="hljs"><code>{
|
<pre class="hljs"><code>{
|
||||||
<span class="hljs-attr">response</span>: {
|
<span class="hljs-attr">response</span>: {
|
||||||
<span class="hljs-attr">statusCode</span>: <span class="hljs-number">200</span>,
|
<span class="hljs-attr">statusCode</span>: <span class="hljs-number">200</span>,
|
||||||
<span class="hljs-attr">header</span>: {
|
<span class="hljs-attr">header</span>: {
|
||||||
<span class="hljs-string">'Content-Type'</span>: <span class="hljs-string">'image/gif'</span>,
|
<span class="hljs-string">'Content-Type'</span>: <span class="hljs-string">'image/gif'</span>,
|
||||||
<span class="hljs-attr">Connection</span>: <span class="hljs-string">'close'</span>,
|
<span class="hljs-attr">Connection</span>: <span class="hljs-string">'close'</span>,
|
||||||
<span class="hljs-string">'Cache-Control'</span>: <span class="hljs-string">'...'</span>
|
<span class="hljs-string">'Cache-Control'</span>: <span class="hljs-string">'...'</span>
|
||||||
@ -396,12 +400,12 @@ newResponse.body += <span class="hljs-string">'--from anyproxy--'</span>;
|
|||||||
<ul class="list">
|
<ul class="list">
|
||||||
<li>AnyProxy will call this method when failed to connect target server in https request</li>
|
<li>AnyProxy will call this method when failed to connect target server in https request</li>
|
||||||
<li><code>requestDetail</code> is the same one as in <code>beforeDealHttpsRequest</code></li>
|
<li><code>requestDetail</code> is the same one as in <code>beforeDealHttpsRequest</code></li>
|
||||||
<li>no return value is required </li>
|
<li>no return value is required</li>
|
||||||
</ul>
|
</ul>
|
||||||
<h3 id="faq"><a class="header-link" href="#faq"></a>FAQ</h3>
|
<h3 id="faq"><a class="header-link" href="#faq"></a>FAQ</h3>
|
||||||
<ul class="list">
|
<ul class="list">
|
||||||
<li>Q: can not deal https request in rule module.</li>
|
<li>Q: can not deal https request in rule module.</li>
|
||||||
<li><p>A: Any of these options could be used to change the way AnyProxy deall https requests </p>
|
<li><p>A: Any of these options could be used to change the way AnyProxy deall https requests</p>
|
||||||
<ol class="list">
|
<ol class="list">
|
||||||
<li>config <code>--intercept</code> when luanching AnyProxy via cli, or use <code>forceProxyHttps</code> when using as an npm module</li>
|
<li>config <code>--intercept</code> when luanching AnyProxy via cli, or use <code>forceProxyHttps</code> when using as an npm module</li>
|
||||||
<li>place a <code>beforeDealHttpsRequest</code> function in your rule file and determine which request to intercept by your own.</li>
|
<li>place a <code>beforeDealHttpsRequest</code> function in your rule file and determine which request to intercept by your own.</li>
|
||||||
@ -683,7 +687,7 @@ proxyServer.close();</code></pre><ul class="list">
|
|||||||
<li>sample</li>
|
<li>sample</li>
|
||||||
</ul>
|
</ul>
|
||||||
<pre class="hljs"><code><span class="hljs-comment">// set 127.0.0.1:8001 as system http server</span>
|
<pre class="hljs"><code><span class="hljs-comment">// set 127.0.0.1:8001 as system http server</span>
|
||||||
AnyProxy.utils.systemProxyMgr.enableGlobalProxy(<span class="hljs-string">'127.0.0.1'</span>, <span class="hljs-string">'8001'</span>);
|
AnyProxy.utils.systemProxyMgr.enableGlobalProxy(<span class="hljs-string">'127.0.0.1'</span>, <span class="hljs-string">'8001'</span>);
|
||||||
|
|
||||||
<span class="hljs-comment">// disable global proxy server</span>
|
<span class="hljs-comment">// disable global proxy server</span>
|
||||||
AnyProxy.utils.systemProxyMgr.disableGlobalProxy();</code></pre></li>
|
AnyProxy.utils.systemProxyMgr.disableGlobalProxy();</code></pre></li>
|
||||||
@ -782,6 +786,36 @@ AnyProxy.utils.systemProxyMgr.disableGlobalProxy();</code></pre></li>
|
|||||||
<li>Android</li>
|
<li>Android</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p class="img-container"><img src="https://zos.alipayobjects.com/rmsportal/YQtbQYVNuOszZGdAOauU.png" width="260" /></p>
|
<p class="img-container"><img src="https://zos.alipayobjects.com/rmsportal/YQtbQYVNuOszZGdAOauU.png" width="260" /></p>
|
||||||
|
<h2 id="faq-1"><a class="header-link" href="#faq-1"></a>FAQ</h2>
|
||||||
|
<h3 id="the-connection-is-not-private"><a class="header-link" href="#the-connection-is-not-private"></a>The connection is not private</h3>
|
||||||
|
<p>AnyProxy will propmt this message when the certificate of the site you're visiting is not issued by a trusted CA.(e.g. <a href="https://github.com/nodejs/node/issues/4175">Node uses an hardcoded list of certificate authorities</a>)</p>
|
||||||
|
<p>You could ignore this kind of error at your own risk. The following is a how-to guide.</p>
|
||||||
|
<ul class="list">
|
||||||
|
<li><p>If you run AnyProxy by command line<br>Pass in the option <code>--ignore-unauthorized-ssl</code> to ignore <strong>all</strong> the certificate errors.</p>
|
||||||
|
<pre class="hljs"><code>anyproxy -i --ignore-unauthorized-ssl</code></pre></li>
|
||||||
|
<li><p>If you run AnyProxy as an npm module<br>Pass in the option <code>dangerouslyIgnoreUnauthorized:true</code>, like this:</p>
|
||||||
|
<pre class="hljs"><code><span class="hljs-keyword">const</span> options = {
|
||||||
|
...,
|
||||||
|
<span class="hljs-attr">dangerouslyIgnoreUnauthorized</span>: <span class="hljs-literal">true</span>
|
||||||
|
};
|
||||||
|
|
||||||
|
<span class="hljs-keyword">const</span> anyproxyIns = <span class="hljs-keyword">new</span> AnyProxy.ProxyCore(options); <span class="hljs-comment">// it would apply to all requests</span>
|
||||||
|
anyproxyIns.start();</code></pre></li>
|
||||||
|
<li><p>With the help of AnyProxy Rule</p>
|
||||||
|
<p>By pass in <code>rejectUnauthorized</code>, you could ignore SSL error in some specified request.</p>
|
||||||
|
<pre class="hljs"><code><span class="hljs-built_in">module</span>.exports = {
|
||||||
|
*beforeSendRequest(requestDetail) {
|
||||||
|
<span class="hljs-keyword">if</span> (requestDetail.url.indexOf(<span class="hljs-string">'https://the-site-you-know.com'</span>) === <span class="hljs-number">0</span>) {
|
||||||
|
<span class="hljs-keyword">const</span> newRequestOptions = requestDetail.requestOptions;
|
||||||
|
<span class="hljs-comment">// set rejectUnauthorized as false</span>
|
||||||
|
newRequestOptions.rejectUnauthorized = <span class="hljs-literal">false</span>;
|
||||||
|
<span class="hljs-keyword">return</span> {
|
||||||
|
<span class="hljs-attr">requestOptions</span>: newRequestOptions
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};</code></pre></li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
|
72
index.html
72
index.html
@ -74,13 +74,15 @@
|
|||||||
<li class="sidebar-header-3"><a href="#trust-root-ca-in-ios">trust root CA in iOS</a></li>
|
<li class="sidebar-header-3"><a href="#trust-root-ca-in-ios">trust root CA in iOS</a></li>
|
||||||
<li class="sidebar-header-3"><a href="#trust-root-ca-in-ios->=-10.3">trust root CA in iOS >= 10.3</a></li>
|
<li class="sidebar-header-3"><a href="#trust-root-ca-in-ios->=-10.3">trust root CA in iOS >= 10.3</a></li>
|
||||||
<li class="sidebar-header-3"><a href="#config-ios/android-proxy-server">config iOS/Android proxy server</a></li>
|
<li class="sidebar-header-3"><a href="#config-ios/android-proxy-server">config iOS/Android proxy server</a></li>
|
||||||
|
<li class="sidebar-header-2"><a href="#faq-1">FAQ</a></li>
|
||||||
|
<li class="sidebar-header-3"><a href="#the-connection-is-not-private">The connection is not private</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="main-content"><h1 id="anyproxy"><a class="header-link" href="#anyproxy"></a>AnyProxy</h1>
|
<div class="main-content"><h1 id="anyproxy"><a class="header-link" href="#anyproxy"></a>AnyProxy</h1>
|
||||||
<p>AnyProxy is a fully configurable http/https proxy in NodeJS. Version 4.0 is in beta now.</p>
|
<p>AnyProxy is a fully configurable http/https proxy in NodeJS. Version 4.0 is in beta now.</p>
|
||||||
<p>Ref: <a href="./cn.html">Chinese Doc 中文文档</a></p>
|
<p>Ref: <a href="./cn.html">Chinese Doc 中文文档</a></p>
|
||||||
<p>Github: </p>
|
<p>Github:</p>
|
||||||
<ul class="list">
|
<ul class="list">
|
||||||
<li><a href="https://github.com/alibaba/anyproxy/tree/4.x">https://github.com/alibaba/anyproxy/tree/4.x</a></li>
|
<li><a href="https://github.com/alibaba/anyproxy/tree/4.x">https://github.com/alibaba/anyproxy/tree/4.x</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -99,6 +101,8 @@
|
|||||||
<p class="img-container"><img src="https://zos.alipayobjects.com/rmsportal/SqVntpzmscXPbSzfcGcr.png" width="500" /></p>
|
<p class="img-container"><img src="https://zos.alipayobjects.com/rmsportal/SqVntpzmscXPbSzfcGcr.png" width="500" /></p>
|
||||||
<h2 id="quick-start"><a class="header-link" href="#quick-start"></a>Quick start</h2>
|
<h2 id="quick-start"><a class="header-link" href="#quick-start"></a>Quick start</h2>
|
||||||
<h3 id="install"><a class="header-link" href="#install"></a>install</h3>
|
<h3 id="install"><a class="header-link" href="#install"></a>install</h3>
|
||||||
|
<p>To Debian and Ubuntu users, you may need to install <code>nodejs-legacy</code> at the same time</p>
|
||||||
|
<pre class="hljs"><code>sudo apg-get install nodejs-legacy</code></pre><p>Then install the AnyProxy</p>
|
||||||
<pre class="hljs"><code>npm install -g anyproxy@beta <span class="hljs-comment"># 4.x is in beta now</span></code></pre><h3 id="launch"><a class="header-link" href="#launch"></a>launch</h3>
|
<pre class="hljs"><code>npm install -g anyproxy@beta <span class="hljs-comment"># 4.x is in beta now</span></code></pre><h3 id="launch"><a class="header-link" href="#launch"></a>launch</h3>
|
||||||
<ul class="list">
|
<ul class="list">
|
||||||
<li>start AnyProxy in command line, with default port 8001</li>
|
<li>start AnyProxy in command line, with default port 8001</li>
|
||||||
@ -172,11 +176,11 @@ anyproxy --intercept <span class="hljs-comment">#launch anyproxy and intercept a
|
|||||||
</li>
|
</li>
|
||||||
<li><p>Step 3, test</p>
|
<li><p>Step 3, test</p>
|
||||||
<ul class="list">
|
<ul class="list">
|
||||||
<li><p>use curl </p>
|
<li><p>use curl</p>
|
||||||
<pre class="hljs"><code>curl http://httpbin.org/user-agent --proxy http://127.0.0.1:8001</code></pre></li>
|
<pre class="hljs"><code>curl http://httpbin.org/user-agent --proxy http://127.0.0.1:8001</code></pre></li>
|
||||||
<li><p>use browser. Point the http proxy of browser to 127.0.0.1:8001, then visit <a href="http://httpbin.org/user-agent">http://httpbin.org/user-agent</a> </p>
|
<li><p>use browser. Point the http proxy of browser to 127.0.0.1:8001, then visit <a href="http://httpbin.org/user-agent">http://httpbin.org/user-agent</a></p>
|
||||||
</li>
|
</li>
|
||||||
<li><p>the expected response from proxy is </p>
|
<li><p>the expected response from proxy is</p>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<pre class="hljs"><code>{
|
<pre class="hljs"><code>{
|
||||||
@ -229,17 +233,17 @@ npm i -g myRulePkg && anyproxy --rule myRulePkg <span class="hljs-commen
|
|||||||
<p>A typical rule module is as follows. All the functions are optional, just write the part you are interested in.</p>
|
<p>A typical rule module is as follows. All the functions are optional, just write the part you are interested in.</p>
|
||||||
<pre class="hljs"><code><span class="hljs-built_in">module</span>.exports = {
|
<pre class="hljs"><code><span class="hljs-built_in">module</span>.exports = {
|
||||||
<span class="hljs-comment">// introduction</span>
|
<span class="hljs-comment">// introduction</span>
|
||||||
summary: <span class="hljs-string">'my customized rule for AnyProxy'</span>,
|
summary: <span class="hljs-string">'my customized rule for AnyProxy'</span>,
|
||||||
<span class="hljs-comment">// intercept before send request to server</span>
|
<span class="hljs-comment">// intercept before send request to server</span>
|
||||||
*beforeSendRequest(requestDetail) { <span class="hljs-comment">/* ... */</span> },
|
*beforeSendRequest(requestDetail) { <span class="hljs-comment">/* ... */</span> },
|
||||||
<span class="hljs-comment">// deal response before send to client </span>
|
<span class="hljs-comment">// deal response before send to client</span>
|
||||||
*beforeSendResponse(requestDetail, responseDetail) { <span class="hljs-comment">/* ... */</span> },
|
*beforeSendResponse(requestDetail, responseDetail) { <span class="hljs-comment">/* ... */</span> },
|
||||||
<span class="hljs-comment">// if deal https request</span>
|
<span class="hljs-comment">// if deal https request</span>
|
||||||
*beforeDealHttpsRequest(requestDetail) { <span class="hljs-comment">/* ... */</span> },
|
*beforeDealHttpsRequest(requestDetail) { <span class="hljs-comment">/* ... */</span> },
|
||||||
<span class="hljs-comment">// error happened when dealing requests</span>
|
<span class="hljs-comment">// error happened when dealing requests</span>
|
||||||
*onError(requestDetail, error) { <span class="hljs-comment">/* ... */</span> },
|
*onError(requestDetail, error) { <span class="hljs-comment">/* ... */</span> },
|
||||||
<span class="hljs-comment">// error happened when connect to https server</span>
|
<span class="hljs-comment">// error happened when connect to https server</span>
|
||||||
*onConnectError(requestDetail, error) { <span class="hljs-comment">/* ... */</span> }
|
*onConnectError(requestDetail, error) { <span class="hljs-comment">/* ... */</span> }
|
||||||
};</code></pre><blockquote>
|
};</code></pre><blockquote>
|
||||||
<p>All functions in your rule file, except summary, are all driven by <a href="https://www.npmjs.com/package/co">co</a> . They should be yieldable, i.e. return a promise or be a generator function.</p>
|
<p>All functions in your rule file, except summary, are all driven by <a href="https://www.npmjs.com/package/co">co</a> . They should be yieldable, i.e. return a promise or be a generator function.</p>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
@ -252,7 +256,7 @@ npm i -g myRulePkg && anyproxy --rule myRulePkg <span class="hljs-commen
|
|||||||
<h4 id="beforesendrequest(requestdetail)"><a class="header-link" href="#beforesendrequest(requestdetail)"></a>beforeSendRequest(requestDetail)</h4>
|
<h4 id="beforesendrequest(requestdetail)"><a class="header-link" href="#beforesendrequest(requestdetail)"></a>beforeSendRequest(requestDetail)</h4>
|
||||||
<ul class="list">
|
<ul class="list">
|
||||||
<li>Before sending request to server, AnyProxy will call <code>beforeSendRequest</code> with param <code>requestDetail</code></li>
|
<li>Before sending request to server, AnyProxy will call <code>beforeSendRequest</code> with param <code>requestDetail</code></li>
|
||||||
<li><code>requestDetail</code> <ul class="list">
|
<li><code>requestDetail</code><ul class="list">
|
||||||
<li><code>protocol</code> {string} the protocol to use, http or https</li>
|
<li><code>protocol</code> {string} the protocol to use, http or https</li>
|
||||||
<li><code>requestOptions</code> {object} the options of the request-to-go, a param of require('http').request . ref: <a href="https://nodejs.org/api/http.html#http_http_request_options_callback">https://nodejs.org/api/http.html#http_http_request_options_callback</a></li>
|
<li><code>requestOptions</code> {object} the options of the request-to-go, a param of require('http').request . ref: <a href="https://nodejs.org/api/http.html#http_http_request_options_callback">https://nodejs.org/api/http.html#http_http_request_options_callback</a></li>
|
||||||
<li><code>requestData</code> {object} request body</li>
|
<li><code>requestData</code> {object} request body</li>
|
||||||
@ -316,16 +320,16 @@ newOption.path = <span class="hljs-string">'/redirect/to/another/path'</span>;
|
|||||||
<ul class="list">
|
<ul class="list">
|
||||||
<li>Before sending response to client, AnyProxy will call <code>beforeSendResponse</code> with param <code>requestDetail</code> <code>responseDetail</code></li>
|
<li>Before sending response to client, AnyProxy will call <code>beforeSendResponse</code> with param <code>requestDetail</code> <code>responseDetail</code></li>
|
||||||
<li><code>requestDetail</code> is the same param as in <code>beforeSendRequest</code></li>
|
<li><code>requestDetail</code> is the same param as in <code>beforeSendRequest</code></li>
|
||||||
<li><code>responseDetail</code> <ul class="list">
|
<li><code>responseDetail</code><ul class="list">
|
||||||
<li><code>response</code> {object} the response from server, includes <code>statusCode</code> <code>header</code> <code>body</code></li>
|
<li><code>response</code> {object} the response from server, includes <code>statusCode</code> <code>header</code> <code>body</code></li>
|
||||||
<li><code>_res</code> {object} the native node.js response object</li>
|
<li><code>_res</code> {object} the native node.js response object</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li><p>e.g. When requesting <em>anyproxy.io</em>, <code>responseDetail</code> is something like the following</p>
|
<li><p>e.g. When requesting <em>anyproxy.io</em>, <code>responseDetail</code> is something like the following</p>
|
||||||
<pre class="hljs"><code>{
|
<pre class="hljs"><code>{
|
||||||
<span class="hljs-attr">response</span>: {
|
<span class="hljs-attr">response</span>: {
|
||||||
<span class="hljs-attr">statusCode</span>: <span class="hljs-number">200</span>,
|
<span class="hljs-attr">statusCode</span>: <span class="hljs-number">200</span>,
|
||||||
<span class="hljs-attr">header</span>: {
|
<span class="hljs-attr">header</span>: {
|
||||||
<span class="hljs-string">'Content-Type'</span>: <span class="hljs-string">'image/gif'</span>,
|
<span class="hljs-string">'Content-Type'</span>: <span class="hljs-string">'image/gif'</span>,
|
||||||
<span class="hljs-attr">Connection</span>: <span class="hljs-string">'close'</span>,
|
<span class="hljs-attr">Connection</span>: <span class="hljs-string">'close'</span>,
|
||||||
<span class="hljs-string">'Cache-Control'</span>: <span class="hljs-string">'...'</span>
|
<span class="hljs-string">'Cache-Control'</span>: <span class="hljs-string">'...'</span>
|
||||||
@ -396,12 +400,12 @@ newResponse.body += <span class="hljs-string">'--from anyproxy--'</span>;
|
|||||||
<ul class="list">
|
<ul class="list">
|
||||||
<li>AnyProxy will call this method when failed to connect target server in https request</li>
|
<li>AnyProxy will call this method when failed to connect target server in https request</li>
|
||||||
<li><code>requestDetail</code> is the same one as in <code>beforeDealHttpsRequest</code></li>
|
<li><code>requestDetail</code> is the same one as in <code>beforeDealHttpsRequest</code></li>
|
||||||
<li>no return value is required </li>
|
<li>no return value is required</li>
|
||||||
</ul>
|
</ul>
|
||||||
<h3 id="faq"><a class="header-link" href="#faq"></a>FAQ</h3>
|
<h3 id="faq"><a class="header-link" href="#faq"></a>FAQ</h3>
|
||||||
<ul class="list">
|
<ul class="list">
|
||||||
<li>Q: can not deal https request in rule module.</li>
|
<li>Q: can not deal https request in rule module.</li>
|
||||||
<li><p>A: Any of these options could be used to change the way AnyProxy deall https requests </p>
|
<li><p>A: Any of these options could be used to change the way AnyProxy deall https requests</p>
|
||||||
<ol class="list">
|
<ol class="list">
|
||||||
<li>config <code>--intercept</code> when luanching AnyProxy via cli, or use <code>forceProxyHttps</code> when using as an npm module</li>
|
<li>config <code>--intercept</code> when luanching AnyProxy via cli, or use <code>forceProxyHttps</code> when using as an npm module</li>
|
||||||
<li>place a <code>beforeDealHttpsRequest</code> function in your rule file and determine which request to intercept by your own.</li>
|
<li>place a <code>beforeDealHttpsRequest</code> function in your rule file and determine which request to intercept by your own.</li>
|
||||||
@ -683,7 +687,7 @@ proxyServer.close();</code></pre><ul class="list">
|
|||||||
<li>sample</li>
|
<li>sample</li>
|
||||||
</ul>
|
</ul>
|
||||||
<pre class="hljs"><code><span class="hljs-comment">// set 127.0.0.1:8001 as system http server</span>
|
<pre class="hljs"><code><span class="hljs-comment">// set 127.0.0.1:8001 as system http server</span>
|
||||||
AnyProxy.utils.systemProxyMgr.enableGlobalProxy(<span class="hljs-string">'127.0.0.1'</span>, <span class="hljs-string">'8001'</span>);
|
AnyProxy.utils.systemProxyMgr.enableGlobalProxy(<span class="hljs-string">'127.0.0.1'</span>, <span class="hljs-string">'8001'</span>);
|
||||||
|
|
||||||
<span class="hljs-comment">// disable global proxy server</span>
|
<span class="hljs-comment">// disable global proxy server</span>
|
||||||
AnyProxy.utils.systemProxyMgr.disableGlobalProxy();</code></pre></li>
|
AnyProxy.utils.systemProxyMgr.disableGlobalProxy();</code></pre></li>
|
||||||
@ -782,6 +786,36 @@ AnyProxy.utils.systemProxyMgr.disableGlobalProxy();</code></pre></li>
|
|||||||
<li>Android</li>
|
<li>Android</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p class="img-container"><img src="https://zos.alipayobjects.com/rmsportal/YQtbQYVNuOszZGdAOauU.png" width="260" /></p>
|
<p class="img-container"><img src="https://zos.alipayobjects.com/rmsportal/YQtbQYVNuOszZGdAOauU.png" width="260" /></p>
|
||||||
|
<h2 id="faq-1"><a class="header-link" href="#faq-1"></a>FAQ</h2>
|
||||||
|
<h3 id="the-connection-is-not-private"><a class="header-link" href="#the-connection-is-not-private"></a>The connection is not private</h3>
|
||||||
|
<p>AnyProxy will propmt this message when the certificate of the site you're visiting is not issued by a trusted CA.(e.g. <a href="https://github.com/nodejs/node/issues/4175">Node uses an hardcoded list of certificate authorities</a>)</p>
|
||||||
|
<p>You could ignore this kind of error at your own risk. The following is a how-to guide.</p>
|
||||||
|
<ul class="list">
|
||||||
|
<li><p>If you run AnyProxy by command line<br>Pass in the option <code>--ignore-unauthorized-ssl</code> to ignore <strong>all</strong> the certificate errors.</p>
|
||||||
|
<pre class="hljs"><code>anyproxy -i --ignore-unauthorized-ssl</code></pre></li>
|
||||||
|
<li><p>If you run AnyProxy as an npm module<br>Pass in the option <code>dangerouslyIgnoreUnauthorized:true</code>, like this:</p>
|
||||||
|
<pre class="hljs"><code><span class="hljs-keyword">const</span> options = {
|
||||||
|
...,
|
||||||
|
<span class="hljs-attr">dangerouslyIgnoreUnauthorized</span>: <span class="hljs-literal">true</span>
|
||||||
|
};
|
||||||
|
|
||||||
|
<span class="hljs-keyword">const</span> anyproxyIns = <span class="hljs-keyword">new</span> AnyProxy.ProxyCore(options); <span class="hljs-comment">// it would apply to all requests</span>
|
||||||
|
anyproxyIns.start();</code></pre></li>
|
||||||
|
<li><p>With the help of AnyProxy Rule</p>
|
||||||
|
<p>By pass in <code>rejectUnauthorized</code>, you could ignore SSL error in some specified request.</p>
|
||||||
|
<pre class="hljs"><code><span class="hljs-built_in">module</span>.exports = {
|
||||||
|
*beforeSendRequest(requestDetail) {
|
||||||
|
<span class="hljs-keyword">if</span> (requestDetail.url.indexOf(<span class="hljs-string">'https://the-site-you-know.com'</span>) === <span class="hljs-number">0</span>) {
|
||||||
|
<span class="hljs-keyword">const</span> newRequestOptions = requestDetail.requestOptions;
|
||||||
|
<span class="hljs-comment">// set rejectUnauthorized as false</span>
|
||||||
|
newRequestOptions.rejectUnauthorized = <span class="hljs-literal">false</span>;
|
||||||
|
<span class="hljs-keyword">return</span> {
|
||||||
|
<span class="hljs-attr">requestOptions</span>: newRequestOptions
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};</code></pre></li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user