1 | https-proxy-agent
|
2 | ================
|
3 | ### An HTTP(s) proxy `http.Agent` implementation for HTTPS
|
4 |
|
5 | This module provides an `http.Agent` implementation that connects to a specified
|
6 | HTTP or HTTPS proxy server, and can be used with the built-in `https` module.
|
7 |
|
8 | Specifically, this `Agent` implementation connects to an intermediary "proxy"
|
9 | server and issues the [CONNECT HTTP method][CONNECT], which tells the proxy to
|
10 | open a direct TCP connection to the destination server.
|
11 |
|
12 | Since this agent implements the CONNECT HTTP method, it also works with other
|
13 | protocols that use this method when connecting over proxies (i.e. WebSockets).
|
14 | See the "Examples" section below for more.
|
15 |
|
16 | Examples
|
17 | --------
|
18 |
|
19 | #### `https` module example
|
20 |
|
21 | ```ts
|
22 | import * as https from 'https';
|
23 | import { HttpsProxyAgent } from 'https-proxy-agent';
|
24 |
|
25 | const agent = new HttpsProxyAgent('http://168.63.76.32:3128');
|
26 |
|
27 | https.get('https://example.com', { agent }, (res) => {
|
28 | console.log('"response" event!', res.headers);
|
29 | res.pipe(process.stdout);
|
30 | });
|
31 | ```
|
32 |
|
33 | #### `ws` WebSocket connection example
|
34 |
|
35 | ```ts
|
36 | import WebSocket from 'ws';
|
37 | import { HttpsProxyAgent } from 'https-proxy-agent';
|
38 |
|
39 | const agent = new HttpsProxyAgent('http://168.63.76.32:3128');
|
40 | const socket = new WebSocket('ws://echo.websocket.org', { agent });
|
41 |
|
42 | socket.on('open', function () {
|
43 | console.log('"open" event!');
|
44 | socket.send('hello world');
|
45 | });
|
46 |
|
47 | socket.on('message', function (data, flags) {
|
48 | console.log('"message" event! %j %j', data, flags);
|
49 | socket.close();
|
50 | });
|
51 | ```
|
52 |
|
53 | API
|
54 | ---
|
55 |
|
56 | ### new HttpsProxyAgent(proxy: string | URL, options?: HttpsProxyAgentOptions)
|
57 |
|
58 | The `HttpsProxyAgent` class implements an `http.Agent` subclass that connects
|
59 | to the specified "HTTP(s) proxy server" in order to proxy HTTPS and/or WebSocket
|
60 | requests. This is achieved by using the [HTTP `CONNECT` method][CONNECT].
|
61 |
|
62 | The `proxy` argument is the URL for the proxy server.
|
63 |
|
64 | The `options` argument accepts the usual `http.Agent` constructor options, and
|
65 | some additional properties:
|
66 |
|
67 | * `headers` - Object containing additional headers to send to the proxy server
|
68 | in the `CONNECT` request.
|
69 |
|
70 |
|
71 | License
|
72 | -------
|
73 |
|
74 | (The MIT License)
|
75 |
|
76 | Copyright (c) 2013 Nathan Rajlich <nathan@tootallnate.net>
|
77 |
|
78 | Permission is hereby granted, free of charge, to any person obtaining
|
79 | a copy of this software and associated documentation files (the
|
80 | 'Software'), to deal in the Software without restriction, including
|
81 | without limitation the rights to use, copy, modify, merge, publish,
|
82 | distribute, sublicense, and/or sell copies of the Software, and to
|
83 | permit persons to whom the Software is furnished to do so, subject to
|
84 | the following conditions:
|
85 |
|
86 | The above copyright notice and this permission notice shall be
|
87 | included in all copies or substantial portions of the Software.
|
88 |
|
89 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
90 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
91 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
92 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
93 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
94 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
95 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
96 |
|
97 | [CONNECT]: http://en.wikipedia.org/wiki/HTTP_tunnel#HTTP_CONNECT_Tunneling
|