1 | # node-tunnel - HTTP/HTTPS Agents for tunneling proxies
|
2 |
|
3 | [![Build Status](https://img.shields.io/travis/koichik/node-tunnel.svg?style=flat)](https://travis-ci.org/koichik/node-tunnel)
|
4 | [![Dependency Status](http://img.shields.io/david/koichik/node-tunnel.svg?style=flat)](https://david-dm.org/koichik/node-tunnel#info=dependencies)
|
5 | [![DevDependency Status](http://img.shields.io/david/dev/koichik/node-tunnel.svg?style=flat)](https://david-dm.org/koichik/node-tunnel#info=devDependencies)
|
6 |
|
7 | ## Example
|
8 |
|
9 | ```javascript
|
10 | var tunnel = require('tunnel');
|
11 |
|
12 | var tunnelingAgent = tunnel.httpsOverHttp({
|
13 | proxy: {
|
14 | host: 'localhost',
|
15 | port: 3128
|
16 | }
|
17 | });
|
18 |
|
19 | var req = https.request({
|
20 | host: 'example.com',
|
21 | port: 443,
|
22 | agent: tunnelingAgent
|
23 | });
|
24 | ```
|
25 |
|
26 | ## Installation
|
27 |
|
28 | $ npm install tunnel
|
29 |
|
30 | ## Usages
|
31 |
|
32 | ### HTTP over HTTP tunneling
|
33 |
|
34 | ```javascript
|
35 | var tunnelingAgent = tunnel.httpOverHttp({
|
36 | maxSockets: poolSize, // Defaults to http.Agent.defaultMaxSockets
|
37 |
|
38 | proxy: { // Proxy settings
|
39 | host: proxyHost, // Defaults to 'localhost'
|
40 | port: proxyPort, // Defaults to 80
|
41 | localAddress: localAddress, // Local interface if necessary
|
42 |
|
43 | // Basic authorization for proxy server if necessary
|
44 | proxyAuth: 'user:password',
|
45 |
|
46 | // Header fields for proxy server if necessary
|
47 | headers: {
|
48 | 'User-Agent': 'Node'
|
49 | }
|
50 | }
|
51 | });
|
52 |
|
53 | var req = http.request({
|
54 | host: 'example.com',
|
55 | port: 80,
|
56 | agent: tunnelingAgent
|
57 | });
|
58 | ```
|
59 |
|
60 | ### HTTPS over HTTP tunneling
|
61 |
|
62 | ```javascript
|
63 | var tunnelingAgent = tunnel.httpsOverHttp({
|
64 | maxSockets: poolSize, // Defaults to http.Agent.defaultMaxSockets
|
65 |
|
66 | // CA for origin server if necessary
|
67 | ca: [ fs.readFileSync('origin-server-ca.pem')],
|
68 |
|
69 | // Client certification for origin server if necessary
|
70 | key: fs.readFileSync('origin-server-key.pem'),
|
71 | cert: fs.readFileSync('origin-server-cert.pem'),
|
72 |
|
73 | proxy: { // Proxy settings
|
74 | host: proxyHost, // Defaults to 'localhost'
|
75 | port: proxyPort, // Defaults to 80
|
76 | localAddress: localAddress, // Local interface if necessary
|
77 |
|
78 | // Basic authorization for proxy server if necessary
|
79 | proxyAuth: 'user:password',
|
80 |
|
81 | // Header fields for proxy server if necessary
|
82 | headers: {
|
83 | 'User-Agent': 'Node'
|
84 | },
|
85 | }
|
86 | });
|
87 |
|
88 | var req = https.request({
|
89 | host: 'example.com',
|
90 | port: 443,
|
91 | agent: tunnelingAgent
|
92 | });
|
93 | ```
|
94 |
|
95 | ### HTTP over HTTPS tunneling
|
96 |
|
97 | ```javascript
|
98 | var tunnelingAgent = tunnel.httpOverHttps({
|
99 | maxSockets: poolSize, // Defaults to http.Agent.defaultMaxSockets
|
100 |
|
101 | proxy: { // Proxy settings
|
102 | host: proxyHost, // Defaults to 'localhost'
|
103 | port: proxyPort, // Defaults to 443
|
104 | localAddress: localAddress, // Local interface if necessary
|
105 |
|
106 | // Basic authorization for proxy server if necessary
|
107 | proxyAuth: 'user:password',
|
108 |
|
109 | // Header fields for proxy server if necessary
|
110 | headers: {
|
111 | 'User-Agent': 'Node'
|
112 | },
|
113 |
|
114 | // CA for proxy server if necessary
|
115 | ca: [ fs.readFileSync('origin-server-ca.pem')],
|
116 |
|
117 | // Server name for verification if necessary
|
118 | servername: 'example.com',
|
119 |
|
120 | // Client certification for proxy server if necessary
|
121 | key: fs.readFileSync('origin-server-key.pem'),
|
122 | cert: fs.readFileSync('origin-server-cert.pem'),
|
123 | }
|
124 | });
|
125 |
|
126 | var req = http.request({
|
127 | host: 'example.com',
|
128 | port: 80,
|
129 | agent: tunnelingAgent
|
130 | });
|
131 | ```
|
132 |
|
133 | ### HTTPS over HTTPS tunneling
|
134 |
|
135 | ```javascript
|
136 | var tunnelingAgent = tunnel.httpsOverHttps({
|
137 | maxSockets: poolSize, // Defaults to http.Agent.defaultMaxSockets
|
138 |
|
139 | // CA for origin server if necessary
|
140 | ca: [ fs.readFileSync('origin-server-ca.pem')],
|
141 |
|
142 | // Client certification for origin server if necessary
|
143 | key: fs.readFileSync('origin-server-key.pem'),
|
144 | cert: fs.readFileSync('origin-server-cert.pem'),
|
145 |
|
146 | proxy: { // Proxy settings
|
147 | host: proxyHost, // Defaults to 'localhost'
|
148 | port: proxyPort, // Defaults to 443
|
149 | localAddress: localAddress, // Local interface if necessary
|
150 |
|
151 | // Basic authorization for proxy server if necessary
|
152 | proxyAuth: 'user:password',
|
153 |
|
154 | // Header fields for proxy server if necessary
|
155 | headers: {
|
156 | 'User-Agent': 'Node'
|
157 | }
|
158 |
|
159 | // CA for proxy server if necessary
|
160 | ca: [ fs.readFileSync('origin-server-ca.pem')],
|
161 |
|
162 | // Server name for verification if necessary
|
163 | servername: 'example.com',
|
164 |
|
165 | // Client certification for proxy server if necessary
|
166 | key: fs.readFileSync('origin-server-key.pem'),
|
167 | cert: fs.readFileSync('origin-server-cert.pem'),
|
168 | }
|
169 | });
|
170 |
|
171 | var req = https.request({
|
172 | host: 'example.com',
|
173 | port: 443,
|
174 | agent: tunnelingAgent
|
175 | });
|
176 | ```
|
177 |
|
178 | ## CONTRIBUTORS
|
179 | * [Aleksis Brezas (abresas)](https://github.com/abresas)
|
180 | * [Jackson Tian (JacksonTian)](https://github.com/JacksonTian)
|
181 | * [Dmitry Sorin (1999)](https://github.com/1999)
|
182 |
|
183 | ## License
|
184 |
|
185 | Licensed under the [MIT](https://github.com/koichik/node-tunnel/blob/master/LICENSE) license.
|