mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-08-04 21:39:04 +00:00
update faq
This commit is contained in:
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->=-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-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>
|
||||
</div>
|
||||
</div>
|
||||
<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>Ref: <a href="./cn.html">Chinese Doc 中文文档</a></p>
|
||||
<p>Github: </p>
|
||||
<p>Github:</p>
|
||||
<ul class="list">
|
||||
<li><a href="https://github.com/alibaba/anyproxy/tree/4.x">https://github.com/alibaba/anyproxy/tree/4.x</a></li>
|
||||
</ul>
|
||||
@@ -99,6 +101,8 @@
|
||||
<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>
|
||||
<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>
|
||||
<ul class="list">
|
||||
<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><p>Step 3, test</p>
|
||||
<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>
|
||||
<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><p>the expected response from proxy is </p>
|
||||
<li><p>the expected response from proxy is</p>
|
||||
</li>
|
||||
</ul>
|
||||
<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>
|
||||
<pre class="hljs"><code><span class="hljs-built_in">module</span>.exports = {
|
||||
<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>
|
||||
*beforeSendRequest(requestDetail) { <span class="hljs-comment">/* ... */</span> },
|
||||
<span class="hljs-comment">// deal response before send to client </span>
|
||||
*beforeSendResponse(requestDetail, responseDetail) { <span class="hljs-comment">/* ... */</span> },
|
||||
*beforeSendRequest(requestDetail) { <span class="hljs-comment">/* ... */</span> },
|
||||
<span class="hljs-comment">// deal response before send to client</span>
|
||||
*beforeSendResponse(requestDetail, responseDetail) { <span class="hljs-comment">/* ... */</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>
|
||||
*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>
|
||||
*onConnectError(requestDetail, error) { <span class="hljs-comment">/* ... */</span> }
|
||||
*onConnectError(requestDetail, error) { <span class="hljs-comment">/* ... */</span> }
|
||||
};</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>
|
||||
</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>
|
||||
<ul class="list">
|
||||
<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>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>
|
||||
@@ -316,16 +320,16 @@ newOption.path = <span class="hljs-string">'/redirect/to/another/path'</span>;
|
||||
<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><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>_res</code> {object} the native node.js response object</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><p>e.g. When requesting <em>anyproxy.io</em>, <code>responseDetail</code> is something like the following</p>
|
||||
<pre class="hljs"><code>{
|
||||
<span class="hljs-attr">response</span>: {
|
||||
<pre class="hljs"><code>{
|
||||
<span class="hljs-attr">response</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-attr">Connection</span>: <span class="hljs-string">'close'</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">
|
||||
<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>no return value is required </li>
|
||||
<li>no return value is required</li>
|
||||
</ul>
|
||||
<h3 id="faq"><a class="header-link" href="#faq"></a>FAQ</h3>
|
||||
<ul class="list">
|
||||
<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">
|
||||
<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>
|
||||
@@ -683,7 +687,7 @@ proxyServer.close();</code></pre><ul class="list">
|
||||
<li>sample</li>
|
||||
</ul>
|
||||
<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>
|
||||
AnyProxy.utils.systemProxyMgr.disableGlobalProxy();</code></pre></li>
|
||||
@@ -782,6 +786,36 @@ AnyProxy.utils.systemProxyMgr.disableGlobalProxy();</code></pre></li>
|
||||
<li>Android</li>
|
||||
</ul>
|
||||
<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>
|
||||
</article>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user