From 3ca8359a21835a22c372c313e7809af407c14008 Mon Sep 17 00:00:00 2001 From: Otto Mao Date: Wed, 3 Sep 2014 19:41:27 +0800 Subject: [PATCH] Create gh-pages branch via GitHub --- index.html | 209 ++++++++++++++++++++++++++++++++++++++++++++++------ params.json | 2 +- 2 files changed, 188 insertions(+), 23 deletions(-) diff --git a/index.html b/index.html index 7f4a7aa..488d5be 100644 --- a/index.html +++ b/index.html @@ -16,7 +16,7 @@

Anyproxy

-

a charles/fiddler like proxy written in NodeJs, which can handle HTTPS requests and CROS perfectly.

+

A fully configurable proxy in NodeJS, which can handle HTTPS requests perfectly.

View the Project on GitHub alipay-ct-wd/anyproxy

@@ -28,37 +28,202 @@
-

-Welcome to GitHub Pages.

+

+anyproxy

-

This automatic page generator is the easiest way to create beautiful pages for all of your projects. Author your page content here using GitHub Flavored Markdown, select a template crafted by a designer, and publish. After your page is generated, you can check out the new branch:

+

A fully configurable proxy in NodeJS, which can handle HTTPS requests perfectly.

-
$ cd your_repo_root/repo_name
-$ git fetch origin
-$ git checkout gh-pages
+

+Feature

+ +
    +
  • work as http or https proxy
  • +
  • fully configurable, you can modify a request at any stage by your own javascript code
  • +
  • when working as https proxy, it can generate and intercept https requests for any domain without complaint by browser (after you trust its root CA)
  • +
  • provide a web interface
  • +

screenshot

+ +

+Usage

+ +

+step 1 - install

+ +
    +
  • install NodeJS +
  • +
  • +npm install -g anyproxy , may require sudo +
  • +

+step 2 - start server

+ +
    +
  • start with default settings : anyproxy +
  • +
  • start with a specific port: anyproxy --port 8001 +
  • +

+step 3 - launch web interface

+ +

+How to write your own rule file

+ +
    +
  • with rule file, you can modify a request at any stage, no matter it's just before sending or after servers' responding.
  • +
  • actually ruleFile.js is a module for Nodejs, feel free to invoke your own modules.
  • +
  • anyproxy --rule /path/to/ruleFile.js
  • +
  • you may learn how it works by our samples: https://github.com/alipay-ct-wd/anyproxy/tree/master/rule_sample +
  • +
  • +

    samples in rule_sample

    + +
      +
    • rule__blank.js, blank rule file with some comments. You may read this before writing your own rule file.

    • +
    • rule_adjust_response_time.js, delay all the response for 1500ms

    • +
    • +rule_allow_CORS.js, add CORS headers to allow cross-domain ajax request
    • +
    • +rule_intercept_some_https_requests.js, intercept https requests toward github.com
    • +
    • +rule_remove_cache_header.js, remove all cache-related headers from server
    • +
    • +rule_replace_request_option.js, replace request parameters before sending to the server
    • +
    • +rule_replace_response_data.js, modify response data
    • +
    • +rule_replace_response_status_code.js, replace server's status code
    • +
    • +rule_use_local_data.js, map some requests to local file
    • +
    +
  • +
  • rule file scheme is as follows, you may also get it from rule__blank.js

  • +
+module.exports = {
+    /*
+    these functions will overwrite the default ones, write your own when necessary.
+    */
+
+    //whether to intercept this request by local logic
+    //if the return value is true, anyproxy will call dealLocalResponse to get response data and will not send request to remote server anymore
+    shouldUseLocalResponse : function(req,reqBody){
+        return false;
+    },
+
+    //you may deal the response locally instead of sending it to server
+    //this function be called when shouldUseLocalResponse returns true
+    //callback(statusCode,resHeader,responseData)
+    //e.g. callback(200,{"content-type":"text/html"},"hello world")
+    dealLocalResponse : function(req,reqBody,callback){
+        callback(statusCode,resHeader,responseData)
+    },
+
+    //replace the request protocol when sending to the real server
+    //protocol : "http" or "https"
+    replaceRequestProtocol:function(req,protocol){
+        var newProtocol = protocol;
+        return newProtocol;
+    },
+
+    //req is user's request sent to the proxy server
+    //option is how the proxy server will send request to the real server. i.e. require("http").request(option,function(){...})
+    //you may return a customized option to replace the original option
+    //you should not write content-length header in options, since anyproxy will handle it for you
+    replaceRequestOption : function(req,option){
+        var newOption = option;
+        return newOption;
+    },
+
+    //replace the request body
+    replaceRequestData: function(req,data){
+        return data;
+    },
+
+    //replace the statusCode before it's sent to the user
+    replaceResponseStatusCode: function(req,res,statusCode){
+        var newStatusCode = statusCode;
+        return newStatusCode;
+    },
+
+    //replace the httpHeader before it's sent to the user
+    //Here header == res.headers
+    replaceResponseHeader: function(req,res,header){
+        var newHeader = header;
+        return newHeader;
+    },
+
+    //replace the response from the server before it's sent to the user
+    //you may return either a Buffer or a string
+    //serverResData is a Buffer, you may get its content by calling serverResData.toString()
+    replaceServerResData: function(req,res,serverResData){
+        return serverResData;
+    },
+
+    //add a pause before sending response to user
+    pauseBeforeSendingResponse : function(req,res){
+        var timeInMS = 1; //delay all requests for 1ms
+        return timeInMS; 
+    },
+
+    //should intercept https request, or it will be forwarded to real server
+    shouldInterceptHttpsReq :function(req){
+        return false;
+    }
+
+};
+
+
+ +

+Using https features

+ +

+step 1 - install openssl

+ +
    +
  • install openssl ,if you want to use HTTPS-related features. After that, the command openssl should be exposed to your shell
  • +

+step 2 - generate a rootCA and trust it

+ +
    +
  • you should do this when it is the first time to start anyproxy
  • +
  • execute anyproxy --root ,follow the instructions on screen
  • +
  • you will see some tip like rootCA generated at : /usr/lib... . cd to that directory, add/trust the rootCA.crt file to your system keychain. In OSX, you may do that by open the *crt file directly
  • +

+step 3 - start a https proxy

+ +
    +
  • anyproxy --type https --host my.domain.com
  • +
  • the param host is required with https proxy and it should be kept exactly what it it when you config your browser. Otherwise, you may get some warning about security.
  • +

+Others

+ +

+work as a module

+ +
npm install anyproxy --save
 
-

If you're using the GitHub for Mac, simply sync your repository and you'll see the new branch.

+
var proxy = require("anyproxy");
 
-

-Designer Templates

+!proxy.isRootCAFileExists() && proxy.generateRootCA(); //please manually trust this rootCA +new proxy.proxyServer("http","8001", "localhost" ,"path/to/rule/file.js"); -

We've crafted some handsome templates for you to use. Go ahead and continue to layouts to browse through them. You can easily go back to edit your page before publishing. After publishing your page, you can revisit the page generator and switch to another theme. Your Page content will be preserved if it remained markdown format.

+
-

-Rather Drive Stick?

+

+clear all the temperary certificates

-

If you prefer to not use the automatic generator, push a branch named gh-pages to your repository to create a page manually. In addition to supporting regular HTML content, GitHub Pages support Jekyll, a simple, blog aware static site generator written by our own Tom Preston-Werner. Jekyll makes it easy to create site-wide headers and footers without having to copy them across every page. It also offers intelligent blog support and other advanced templating features.

+

anyproxy --clear

-

-Authors and Contributors

+

+Contact

-

You can @mention a GitHub username to generate a link to their profile. The resulting <a> element will link to the contributor's GitHub Profile. For example: In 2007, Chris Wanstrath (@defunkt), PJ Hyett (@pjhyett), and Tom Preston-Werner (@mojombo) founded GitHub.

- -

-Support or Contact

- -

Having trouble with Pages? Check out the documentation at http://help.github.com/pages or contact support@github.com and we’ll help you sort it out.

+
    +
  • Please feel free to raise any issue about this project, or give us some advice on this doc. :)
  • +