README.md
  1  proxy-agent
  2  ===========
  3  ### Maps proxy protocols to `http.Agent` implementations
  4  [![Build Status](https://travis-ci.org/TooTallNate/node-proxy-agent.svg?branch=master)](https://travis-ci.org/TooTallNate/node-proxy-agent)
  5  
  6  This module provides a function that returns proxying `http.Agent` instances to
  7  use based off of a given proxy URI. If no URI is provided, then
  8  [proxy-from-env](https://www.npmjs.com/package/proxy-from-env) is used to get the URI
  9  from `$HTTP_PROXY`, `$HTTPS_PROXY` and `$NO_PROXY` among others.
 10  
 11  An LRU cache is used so that `http.Agent` instances are transparently re-used for
 12  subsequent HTTP requests to the same proxy server.
 13  
 14  The currently implemented protocol mappings are listed in the table below:
 15  
 16  
 17  | Protocol   | Proxy Agent for `http` requests | Proxy Agent for `https` requests | Example
 18  |:----------:|:-------------------------------:|:--------------------------------:|:--------:
 19  | `http`     | [http-proxy-agent][]            | [https-proxy-agent][]            | `http://proxy-server-over-tcp.com:3128`
 20  | `https`    | [http-proxy-agent][]            | [https-proxy-agent][]            | `https://proxy-server-over-tls.com:3129`
 21  | `socks(v5)`| [socks-proxy-agent][]           | [socks-proxy-agent][]            | `socks://username:password@some-socks-proxy.com:9050` (username & password are optional)
 22  | `socks5`   | [socks-proxy-agent][]           | [socks-proxy-agent][]            | `socks5://username:password@some-socks-proxy.com:9050` (username & password are optional)
 23  | `socks4`   | [socks-proxy-agent][]           | [socks-proxy-agent][]            | `socks4://some-socks-proxy.com:9050`
 24  | `pac`      | [pac-proxy-agent][]             | [pac-proxy-agent][]              | `pac+http://www.example.com/proxy.pac`
 25  
 26  
 27  Installation
 28  ------------
 29  
 30  Install with `npm`:
 31  
 32  ``` bash
 33  $ npm install proxy-agent
 34  ```
 35  
 36  
 37  Example
 38  -------
 39  
 40  ``` js
 41  var http = require('http');
 42  var ProxyAgent = require('proxy-agent');
 43  
 44  // HTTP, HTTPS, or SOCKS proxy to use
 45  var proxyUri = process.env.http_proxy || 'http://168.63.43.102:3128';
 46  
 47  var opts = {
 48    method: 'GET',
 49    host: 'jsonip.org',
 50    path: '/',
 51    // this is the important part!
 52    // If no proxyUri is specified, then https://www.npmjs.com/package/proxy-from-env
 53    // is used to get the proxyUri.
 54    agent: new ProxyAgent(proxyUri)
 55  };
 56  
 57  // the rest works just like any other normal HTTP request
 58  http.get(opts, onresponse);
 59  
 60  function onresponse (res) {
 61    console.log(res.statusCode, res.headers);
 62    res.pipe(process.stdout);
 63  }
 64  ```
 65  
 66  
 67  API
 68  ---
 69  
 70  ### new ProxyAgent(Object|String opts|uri)
 71  
 72  Returns an `http.Agent` instance based off of the given proxy `opts` or URI
 73  string. An LRU cache is used, so the same `http.Agent` instance will be
 74  returned if identical args are passed in.
 75  
 76  
 77  License
 78  -------
 79  
 80  (The MIT License)
 81  
 82  Copyright (c) 2013 Nathan Rajlich <nathan@tootallnate.net>
 83  
 84  Permission is hereby granted, free of charge, to any person obtaining
 85  a copy of this software and associated documentation files (the
 86  'Software'), to deal in the Software without restriction, including
 87  without limitation the rights to use, copy, modify, merge, publish,
 88  distribute, sublicense, and/or sell copies of the Software, and to
 89  permit persons to whom the Software is furnished to do so, subject to
 90  the following conditions:
 91  
 92  The above copyright notice and this permission notice shall be
 93  included in all copies or substantial portions of the Software.
 94  
 95  THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
 96  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 97  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 98  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 99  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
100  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
101  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
102  
103  
104  [http-proxy-agent]: https://github.com/TooTallNate/node-http-proxy-agent
105  [https-proxy-agent]: https://github.com/TooTallNate/node-https-proxy-agent
106  [socks-proxy-agent]: https://github.com/TooTallNate/node-socks-proxy-agent
107  [pac-proxy-agent]: https://github.com/TooTallNate/node-pac-proxy-agent