@dev-swarup/http-mitm-proxy 0.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.editorconfig ADDED
@@ -0,0 +1,17 @@
1
+ # Editor configuration, see http://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ charset = utf-8
6
+ indent_style = space
7
+ indent_size = 2
8
+ insert_final_newline = true
9
+ trim_trailing_whitespace = true
10
+
11
+ [*.js]
12
+ quote_type = single
13
+ max_line_length = 200
14
+
15
+ [*.md]
16
+ max_line_length = off
17
+ trim_trailing_whitespace = false
package/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # The test files should be treated as binary to prevent LF/CRLF conversion on windows.
2
+ *.bin binary
@@ -0,0 +1,23 @@
1
+ # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
+
4
+ name: Node.js Package
5
+
6
+ on:
7
+ push:
8
+ release:
9
+ types: [created]
10
+
11
+ jobs:
12
+ publish-npm:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v3
16
+ - uses: actions/setup-node@v3
17
+ with:
18
+ node-version: 16
19
+ registry-url: https://registry.npmjs.org/
20
+ - run: npm i
21
+ - run: npm publish --access public
22
+ env:
23
+ NODE_AUTH_TOKEN: ${{secrets.npm_token}}
@@ -0,0 +1,63 @@
1
+ # This is a composition of lint and test scripts
2
+ # Make sure to update this file along with the others
3
+
4
+ name: Tests
5
+
6
+ # Run this job on all pushes and pull requests
7
+ # as well as tags with a semantic version
8
+ on:
9
+ push:
10
+ branches:
11
+ - "*"
12
+ tags:
13
+ # normal versions
14
+ - "v?[0-9]+.[0-9]+.[0-9]+"
15
+ # pre-releases
16
+ - "v?[0-9]+.[0-9]+.[0-9]+-**"
17
+ pull_request: {}
18
+
19
+ jobs:
20
+ # Performs quick checks before the expensive test runs
21
+ check-and-lint:
22
+ if: contains(github.event.head_commit.message, '[skip ci]') == false
23
+
24
+ runs-on: ubuntu-latest
25
+
26
+ strategy:
27
+ matrix:
28
+ node-version: [18]
29
+
30
+ steps:
31
+ - uses: actions/checkout@v1
32
+ - name: Use Node.js ${{ matrix.node-version }}
33
+ uses: actions/setup-node@v2.2.0
34
+ with:
35
+ node-version: ${{ matrix.node-version }}
36
+
37
+ - name: Install Dependencies
38
+ run: npm install
39
+
40
+ # Runs library tests on all supported node versions and OSes
41
+ lib-tests:
42
+ if: contains(github.event.head_commit.message, '[skip ci]') == false
43
+
44
+ needs: [check-and-lint]
45
+
46
+ runs-on: ${{ matrix.os }}
47
+ strategy:
48
+ matrix:
49
+ node-version: [18, 20, 22]
50
+ os: [ubuntu-latest, windows-latest, macos-latest]
51
+
52
+ steps:
53
+ - uses: actions/checkout@v1
54
+ - name: Use Node.js ${{ matrix.node-version }}
55
+ uses: actions/setup-node@v2.2.0
56
+ with:
57
+ node-version: ${{ matrix.node-version }}
58
+
59
+ - name: Install Dependencies
60
+ run: npm install
61
+
62
+ - name: Run local tests
63
+ run: npm test
package/README.md ADDED
@@ -0,0 +1,555 @@
1
+ # @bjowes fork
2
+
3
+ This is a fork of Joe Ferners' library node-http-mitm-proxy (see docs below). Its first release was identical to the master version of the original library, commit 66ac0f5d3298f66b731f90ebf1e9b430fa5d76eb. I decided to publish a scoped version of this library to npm, since I needed the codebase in npm. It is only intended for my own library cypress-ntlm-auth. Use at you own risk!
4
+
5
+ * 2025-01-27: 0.9.6 - Dependency bump
6
+ * 2024-03-27: 0.9.5 - Patch for custom status messages, dependency bump
7
+ * 2022-04-08: 0.9.4 - Address accessor, typings fix
8
+ * 2022-04-04: 0.9.3 - Patch for cert filenames with IPv6 sites.
9
+ * 2022-03-31: 0.9.2 - Updated dependencies due to security issues. Improved HTTPS stability. IPv6 Support.
10
+ * 2019-08-01: Updated dependencies due to security issues
11
+
12
+ # @dev-swarup fork
13
+ This is a fork of bjowes' library node-http-mitm-proxy. This release was made to remove the certificate saving on the disk.
14
+
15
+ # HTTP MITM Proxy
16
+
17
+ HTTP Man In The Middle (MITM) Proxy written in node.js. Supports capturing and modifying the request and response data.
18
+
19
+ [![NPM version](http://img.shields.io/npm/v/@dev-swarup/http-mitm-proxy.svg)](https://www.npmjs.com/package/@dev-swarup/http-mitm-proxy)
20
+ [![Downloads](https://img.shields.io/npm/dm/@dev-swarup/http-mitm-proxy.svg)](https://www.npmjs.com/package/@dev-swarup/http-mitm-proxy)
21
+ ![Test Status](https://github.com/@dev-swarup/http-mitm-proxy/workflows/Tests/badge.svg)
22
+
23
+ # Install
24
+
25
+ `npm install --save @dev-swarup/http-mitm-proxy`
26
+
27
+ ## Node.js Compatibility
28
+ The library should work starting Node.js 8.x, but testing is only expected for currently supported LTS versions of Node.js starting Node.js 12.x . use on your own risk with non LTS Node.js versions.
29
+
30
+ ## Typescript
31
+ type definitions are now included in this project, no extra steps required.
32
+
33
+ # Example
34
+
35
+ This example will modify any search results coming from google and replace all the result titles with "Pwned!".
36
+
37
+ ```javascript
38
+ var Proxy = require('@dev-swarup/http-mitm-proxy');
39
+ var proxy = Proxy();
40
+
41
+ proxy.onError(function(ctx, err) {
42
+ console.error('proxy error:', err);
43
+ });
44
+
45
+ proxy.onRequest(function(ctx, callback) {
46
+ if (ctx.clientToProxyRequest.headers.host == 'www.google.com'
47
+ && ctx.clientToProxyRequest.url.indexOf('/search') == 0) {
48
+ ctx.use(Proxy.gunzip);
49
+
50
+ ctx.onResponseData(function(ctx, chunk, callback) {
51
+ chunk = new Buffer(chunk.toString().replace(/<h3.*?<\/h3>/g, '<h3>Pwned!</h3>'));
52
+ return callback(null, chunk);
53
+ });
54
+ }
55
+ return callback();
56
+ });
57
+
58
+ proxy.listen({port: 8081});
59
+ ```
60
+
61
+ You can find more examples in the [examples directory](https://github.com/@dev-swarup/http-mitm-proxy/tree/master/examples)
62
+
63
+ # SSL
64
+
65
+ Using node-forge allows the automatic generation of SSL certificates within the proxy. After running your app you will find options.sslCaDir + '/certs/ca.pem' which can be imported to your browser, phone, etc.
66
+
67
+ # API
68
+
69
+ ## Proxy
70
+ * [listen(options)](#proxy_listen)
71
+ * [close](#proxy_close)
72
+ * [onError(fn)](#proxy_onError)
73
+ * [onCertificateRequired](#proxy_onCertificateRequired)
74
+ * [onCertificateMissing](#proxy_onCertificateMissing)
75
+ * [onRequest(fn)](#proxy_onRequest)
76
+ * [onRequestData(fn)](#proxy_onRequestData)
77
+ * [onRequestEnd(fn)](#proxy_onRequestEnd)
78
+ * [onResponse(fn)](#proxy_onResponse)
79
+ * [onResponseData(fn)](#proxy_onResponseData)
80
+ * [onResponseEnd(fn)](#proxy_onResponseEnd)
81
+ * [onWebSocketConnection(fn)](#proxy_onWebSocketConnection)
82
+ * [onWebSocketSend(fn)](#proxy_onWebSocketSend)
83
+ * [onWebSocketMessage(fn)](#proxy_onWebSocketMessage)
84
+ * [onWebSocketFrame(fn)](#proxy_onWebSocketFrame)
85
+ * [onWebSocketError(fn)](#proxy_onWebSocketError)
86
+ * [onWebSocketClose(fn)](#proxy_onWebSocketClose)
87
+ * [use(fn)](#proxy_use)
88
+
89
+ ## Context
90
+
91
+ Context functions only effect the current request/response. For example you may only want to gunzip requests
92
+ made to a particular host.
93
+
94
+ * isSSL: boolean,
95
+ * clientToProxyRequest: [IncomingMessage](https://nodejs.org/api/http.html#http_http_incomingmessage),
96
+ * proxyToClientResponse: [ServerResponse](https://nodejs.org/api/http.html#http_class_http_serverresponse),
97
+ * proxyToServerRequest: [ClientRequest](https://nodejs.org/api/http.html#http_class_http_clientrequest),
98
+ * serverToProxyResponse: [IncomingMessage](https://nodejs.org/api/http.html#http_http_incomingmessage),
99
+ * [onError(fn)](#proxy_onError)
100
+ * [onRequest(fn)](#proxy_onRequest)
101
+ * [onRequestData(fn)](#proxy_onRequestData)
102
+ * [onRequestEnd(fn)](#proxy_onRequestEnd)
103
+ * [addRequestFilter(fn)](#context_addRequestFilter)
104
+ * [onResponse(fn)](#proxy_onResponse)
105
+ * [onResponseData(fn)](#proxy_onResponseData)
106
+ * [onResponseEnd(fn)](#proxy_onResponseEnd)
107
+ * [addResponseFilter(fn)](#context_addResponseFilter)
108
+ * [use(mod)](#proxy_use)
109
+
110
+ ## WebSocket Context
111
+
112
+ The context available in websocket handlers is a bit different
113
+
114
+ * isSSL: boolean,
115
+ * clientToProxyWebSocket: [WebSocket](https://github.com/websockets/ws/blob/master/doc/ws.md#class-wswebsocket),
116
+ * proxyToServerWebSocket: [WebSocket](https://github.com/websockets/ws/blob/master/doc/ws.md#class-wswebsocket),
117
+ * [onWebSocketConnection(fn)](#proxy_onWebSocketConnection)
118
+ * [onWebSocketSend(fn)](#proxy_onWebSocketSend)
119
+ * [onWebSocketMessage(fn)](#proxy_onWebSocketMessage)
120
+ * [onWebSocketFrame(fn)](#proxy_onWebSocketFrame)
121
+ * [onWebSocketError(fn)](#proxy_onWebSocketError)
122
+ * [onWebSocketClose(fn)](#proxy_onWebSocketClose)
123
+ * [use(mod)](#proxy_use)
124
+
125
+ <a name="proxy"/>
126
+
127
+ ## Proxy
128
+
129
+ <a name="proxy_listen" />
130
+
131
+ ### proxy.listen
132
+
133
+ Starts the proxy listening on the given port.
134
+
135
+ __Arguments__
136
+
137
+ * options - An object with the following options:
138
+ * port - The port or named socket to listen on (default: 8080).
139
+ * host - The hostname or local address to listen on (default: 'localhost'). Pass '::' to listen on all IPv4/IPv6 interfaces.
140
+ * sslCaDir - Path to the certificates cache directory (default: process.cwd() + '/.http-mitm-proxy')
141
+ * keepAlive - enable [HTTP persistent connection](https://en.wikipedia.org/wiki/HTTP_persistent_connection)
142
+ * timeout - The number of milliseconds of inactivity before a socket is presumed to have timed out. Defaults to no timeout.
143
+ * httpAgent - The [http.Agent](https://nodejs.org/api/http.html#http_class_http_agent) to use when making http requests. Useful for chaining proxys. (default: internal Agent)
144
+ * httpsAgent - The [https.Agent](https://nodejs.org/api/https.html#https_class_https_agent) to use when making https requests. Useful for chaining proxys. (default: internal Agent)
145
+ * forceSNI - force use of [SNI](https://en.wikipedia.org/wiki/Server_Name_Indication) by the client. Allow node-http-mitm-proxy to handle all HTTPS requests with a single internal server.
146
+ * httpsPort - The port or named socket for https server to listen on. _(forceSNI must be enabled)_
147
+ * forceChunkedRequest - Setting this option will remove the content-length from the proxy to server request, forcing chunked encoding.
148
+
149
+ __Example__
150
+
151
+ proxy.listen({ port: 80 });
152
+
153
+ <a name="proxy_close" />
154
+
155
+ ### proxy.close
156
+
157
+ Stops the proxy listening.
158
+
159
+ __Example__
160
+
161
+ proxy.close();
162
+
163
+ <a name="proxy_onError" />
164
+
165
+ ### proxy.onError(fn) or ctx.onError(fn)
166
+
167
+ Adds a function to the list of functions to get called if an error occures.
168
+
169
+ __Arguments__
170
+
171
+ * fn(ctx, err, errorKind) - The function to be called on an error.
172
+
173
+ __Example__
174
+
175
+ proxy.onError(function(ctx, err, errorKind) {
176
+ // ctx may be null
177
+ var url = (ctx && ctx.clientToProxyRequest) ? ctx.clientToProxyRequest.url : "";
178
+ console.error(errorKind + ' on ' + url + ':', err);
179
+ });
180
+
181
+ <a name="proxy_onCertificateRequired" />
182
+
183
+ ### proxy.onCertificateRequired = function(hostname, callback)
184
+
185
+ Allows the default certificate name/path computation to be overwritten.
186
+
187
+ The default behavior expects `keys/{hostname}.pem` and `certs/{hostname}.pem` files to be at `self.sslCaDir`.
188
+
189
+ __Arguments__
190
+
191
+ * hostname - Requested hostname.
192
+ * callback - The function to be called when certificate files' path were already computed.
193
+
194
+ __Example 1__
195
+
196
+ proxy.onCertificateRequired = function(hostname, callback) {
197
+ return callback(null, {
198
+ keyFile: path.resolve('/ca/certs/', hostname + '.key'),
199
+ certFile: path.resolve('/ca/certs/', hostname + '.crt')
200
+ });
201
+ };
202
+
203
+ __Example 2: Wilcard certificates__
204
+
205
+ proxy.onCertificateRequired = function(hostname, callback) {
206
+ return callback(null, {
207
+ keyFile: path.resolve('/ca/certs/', hostname + '.key'),
208
+ certFile: path.resolve('/ca/certs/', hostname + '.crt'),
209
+ hosts: ["*.mydomain.com"]
210
+ });
211
+ };
212
+
213
+
214
+ <a name="proxy_onCertificateMissing" />
215
+
216
+ ### proxy.onCertificateMissing = function(ctx, files, callback)
217
+
218
+ Allows you to handle missing certificate files for current request, for example, creating them on the fly.
219
+
220
+ __Arguments__
221
+
222
+ * ctx - Context with the following properties
223
+ * hostname - The hostname which requires certificates
224
+ * data.keyFileExists - Whether key file exists or not
225
+ * data.certFileExists - Whether certificate file exists or not
226
+ * files - missing files names (`files.keyFile`, `files.certFile` and optional `files.hosts`)
227
+ * callback - The function to be called to pass certificate data back (`keyFileData` and `certFileData`)
228
+
229
+ __Example 1__
230
+
231
+ proxy.onCertificateMissing = function(ctx, files, callback) {
232
+ console.log('Looking for "%s" certificates', ctx.hostname);
233
+ console.log('"%s" missing', ctx.files.keyFile);
234
+ console.log('"%s" missing', ctx.files.certFile);
235
+
236
+ // Here you have the last chance to provide certificate files data
237
+ // A tipical use case would be creating them on the fly
238
+ //
239
+ // return callback(null, {
240
+ // keyFileData: keyFileData,
241
+ // certFileData: certFileData
242
+ // });
243
+ };
244
+
245
+ __Example 2: Wilcard certificates__
246
+
247
+ proxy.onCertificateMissing = function(ctx, files, callback) {
248
+ return callback(null, {
249
+ keyFileData: keyFileData,
250
+ certFileData: certFileData,
251
+ hosts: ["*.mydomain.com"]
252
+ });
253
+ };
254
+
255
+
256
+ <a name="proxy_onRequest" />
257
+
258
+ ### proxy.onRequest(fn) or ctx.onRequest(fn)
259
+
260
+ Adds a function to get called at the beginning of a request.
261
+
262
+ __Arguments__
263
+
264
+ * fn(ctx, callback) - The function that gets called on each request.
265
+
266
+ __Example__
267
+
268
+ proxy.onRequest(function(ctx, callback) {
269
+ console.log('REQUEST:', ctx.clientToProxyRequest.url);
270
+ return callback();
271
+ });
272
+
273
+ <a name="proxy_onRequestData" />
274
+
275
+ ### proxy.onRequestData(fn) or ctx.onRequestData(fn)
276
+
277
+ Adds a function to get called for each request data chunk (the body).
278
+
279
+ __Arguments__
280
+
281
+ * fn(ctx, chunk, callback) - The function that gets called for each data chunk.
282
+
283
+ __Example__
284
+
285
+ proxy.onRequestData(function(ctx, chunk, callback) {
286
+ console.log('REQUEST DATA:', chunk.toString());
287
+ return callback(null, chunk);
288
+ });
289
+
290
+ <a name="proxy_onRequestEnd" />
291
+
292
+ ### proxy.onRequestEnd(fn) or ctx.onRequestEnd(fn)
293
+
294
+ Adds a function to get called when all request data (the body) was sent.
295
+
296
+ __Arguments__
297
+
298
+ * fn(ctx, callback) - The function that gets called when all request data (the body) was sent.
299
+
300
+ __Example__
301
+
302
+ var chunks = [];
303
+
304
+ proxy.onRequestData(function(ctx, chunk, callback) {
305
+ chunks.push(chunk);
306
+ return callback(null, chunk);
307
+ });
308
+
309
+ proxy.onRequestEnd(function(ctx, callback) {
310
+ console.log('REQUEST END', (Buffer.concat(chunks)).toString());
311
+ return callback();
312
+ });
313
+
314
+ <a name="proxy_onResponse" />
315
+
316
+ ### proxy.onResponse(fn) or ctx.onResponse(fn)
317
+
318
+ Adds a function to get called at the beginning of the response.
319
+
320
+ __Arguments__
321
+
322
+ * fn(ctx, callback) - The function that gets called on each response.
323
+
324
+ __Example__
325
+
326
+ proxy.onResponse(function(ctx, callback) {
327
+ console.log('BEGIN RESPONSE');
328
+ return callback();
329
+ });
330
+
331
+ <a name="proxy_onResponseData" />
332
+
333
+ ### proxy.onResponseData(fn) or ctx.onResponseData(fn)
334
+
335
+ Adds a function to get called for each response data chunk (the body).
336
+
337
+ __Arguments__
338
+
339
+ * fn(ctx, chunk, callback) - The function that gets called for each data chunk.
340
+
341
+ __Example__
342
+
343
+ proxy.onResponseData(function(ctx, chunk, callback) {
344
+ console.log('RESPONSE DATA:', chunk.toString());
345
+ return callback(null, chunk);
346
+ });
347
+
348
+ <a name="proxy_onResponseEnd" />
349
+
350
+ ### proxy.onResponseEnd(fn) or ctx.onResponseEnd(fn)
351
+
352
+ Adds a function to get called when the proxy request to server has ended.
353
+
354
+ __Arguments__
355
+
356
+ * fn(ctx, callback) - The function that gets called when the proxy request to server as ended.
357
+
358
+ __Example__
359
+
360
+ proxy.onResponseEnd(function(ctx, callback) {
361
+ console.log('RESPONSE END');
362
+ return callback();
363
+ });
364
+
365
+ <a name="proxy_onWebSocketConnection" />
366
+
367
+ ### proxy.onWebSocketConnection(fn) or ctx.onWebSocketConnection(fn)
368
+
369
+ Adds a function to get called at the beginning of websocket connection
370
+
371
+ __Arguments__
372
+
373
+ * fn(ctx, callback) - The function that gets called for each data chunk.
374
+
375
+ __Example__
376
+
377
+ proxy.onWebSocketConnection(function(ctx, callback) {
378
+ console.log('WEBSOCKET CONNECT:', ctx.clientToProxyWebSocket.upgradeReq.url);
379
+ return callback();
380
+ });
381
+
382
+ <a name="proxy_onWebSocketSend" />
383
+
384
+ ### proxy.onWebSocketSend(fn) or ctx.onWebSocketSend(fn)
385
+
386
+ Adds a function to get called for each WebSocket message sent by the client.
387
+
388
+ __Arguments__
389
+
390
+ * fn(ctx, message, flags, callback) - The function that gets called for each WebSocket message sent by the client.
391
+
392
+ __Example__
393
+
394
+ proxy.onWebSocketSend(function(ctx, message, flags, callback) {
395
+ console.log('WEBSOCKET SEND:', ctx.clientToProxyWebSocket.upgradeReq.url, message);
396
+ return callback(null, message, flags);
397
+ });
398
+
399
+ <a name="proxy_onWebSocketMessage" />
400
+
401
+ ### proxy.onWebSocketMessage(fn) or ctx.onWebSocketMessage(fn)
402
+
403
+ Adds a function to get called for each WebSocket message received from the server.
404
+
405
+ __Arguments__
406
+
407
+ * fn(ctx, message, flags, callback) - The function that gets called for each WebSocket message received from the server.
408
+
409
+ __Example__
410
+
411
+ proxy.onWebSocketMessage(function(ctx, message, flags, callback) {
412
+ console.log('WEBSOCKET MESSAGE:', ctx.clientToProxyWebSocket.upgradeReq.url, message);
413
+ return callback(null, message, flags);
414
+ });
415
+
416
+ <a name="proxy_onWebSocketFrame" />
417
+
418
+ ### proxy.onWebSocketFrame(fn) or ctx.onWebSocketFrame(fn)
419
+
420
+ Adds a function to get called for each WebSocket frame exchanged (`message`, `ping` or `pong`).
421
+
422
+ __Arguments__
423
+
424
+ * fn(ctx, type, fromServer, data, flags, callback) - The function that gets called for each WebSocket frame exchanged.
425
+
426
+ __Example__
427
+
428
+ proxy.onWebSocketFrame(function(ctx, type, fromServer, data, flags, callback) {
429
+ console.log('WEBSOCKET FRAME ' + type + ' received from ' + (fromServer ? 'server' : 'client'), ctx.clientToProxyWebSocket.upgradeReq.url, data);
430
+ return callback(null, data, flags);
431
+ });
432
+
433
+ <a name="proxy_onWebSocketError" />
434
+
435
+ ### proxy.onWebSocketError(fn) or ctx.onWebSocketError(fn)
436
+
437
+ Adds a function to the list of functions to get called if an error occures in WebSocket.
438
+
439
+ __Arguments__
440
+
441
+ * fn(ctx, err) - The function to be called on an error in WebSocket.
442
+
443
+ __Example__
444
+
445
+ proxy.onWebSocketError(function(ctx, err) {
446
+ console.log('WEBSOCKET ERROR:', ctx.clientToProxyWebSocket.upgradeReq.url, err);
447
+ });
448
+
449
+ <a name="proxy_onWebSocketClose" />
450
+
451
+ ### proxy.onWebSocketClose(fn) or ctx.onWebSocketClose(fn)
452
+
453
+ Adds a function to get called when a WebSocket connection is closed
454
+
455
+ __Arguments__
456
+
457
+ * fn(ctx, code, message, callback) - The function that gets when a WebSocket is closed.
458
+
459
+ __Example__
460
+
461
+ proxy.onWebSocketClose(function(ctx, code, message, callback) {
462
+ console.log('WEBSOCKET CLOSED BY '+(ctx.closedByServer ? 'SERVER' : 'CLIENT'), ctx.clientToProxyWebSocket.upgradeReq.url, code, message);
463
+ callback(null, code, message);
464
+ });
465
+
466
+ <a name="proxy_use" />
467
+
468
+ ### proxy.use(module) or ctx.use(module)
469
+
470
+ Adds a module into the proxy. Modules encapsulate multiple life cycle processing functions into one object.
471
+
472
+ __Arguments__
473
+
474
+ * module - The module to add. Modules contain a hash of functions to add.
475
+
476
+ __Example__
477
+
478
+ proxy.use({
479
+ onError: function(ctx, err) { },
480
+ onCertificateRequired: function(hostname, callback) { return callback(); },
481
+ onCertificateMissing: function(ctx, files, callback) { return callback(); },
482
+ onRequest: function(ctx, callback) { return callback(); },
483
+ onRequestData: function(ctx, chunk, callback) { return callback(null, chunk); },
484
+ onResponse: function(ctx, callback) { return callback(); },
485
+ onResponseData: function(ctx, chunk, callback) { return callback(null, chunk); },
486
+ onWebSocketConnection: function(ctx, callback) { return callback(); },
487
+ onWebSocketSend: function(ctx, message, flags, callback) { return callback(null, message, flags); },
488
+ onWebSocketMessage: function(ctx, message, flags, callback) { return callback(null, message, flags); },
489
+ onWebSocketError: function(ctx, err) { },
490
+ onWebSocketClose: function(ctx, code, message, callback) { },
491
+ });
492
+
493
+ node-http-mitm-proxy provide some ready to use modules:
494
+ - `Proxy.gunzip` Gunzip response filter (uncompress gzipped content before onResponseData and compress back after)
495
+ - `Proxy.wildcard` Generates wilcard certificates by default (so less certificates are generated)
496
+
497
+ <a name="context"/>
498
+
499
+ ## Context
500
+
501
+ <a name="context_addRequestFilter" />
502
+
503
+ ### ctx.addRequestFilter(stream)
504
+
505
+ Adds a stream into the request body stream.
506
+
507
+ __Arguments__
508
+
509
+ * stream - The read/write stream to add in the request body stream.
510
+
511
+ __Example__
512
+
513
+ ctx.addRequestFilter(zlib.createGunzip());
514
+
515
+ <a name="context_addRequestFilter" />
516
+
517
+ ### ctx.addResponseFilter(stream)
518
+
519
+ Adds a stream into the response body stream.
520
+
521
+ __Arguments__
522
+
523
+ * stream - The read/write stream to add in the response body stream.
524
+
525
+ __Example__
526
+
527
+ ctx.addResponseFilter(zlib.createGunzip());
528
+
529
+ # License
530
+
531
+ ```
532
+ Copyright (c) 2015 Joe Ferner
533
+
534
+ Permission is hereby granted, free of charge, to any person obtaining a copy
535
+ of this software and associated documentation files (the "Software"), to deal
536
+ in the Software without restriction, including without limitation the rights
537
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
538
+ copies of the Software, and to permit persons to whom the Software is
539
+ furnished to do so, subject to the following conditions:
540
+
541
+
542
+
543
+ The above copyright notice and this permission notice shall be included in
544
+ all copies or substantial portions of the Software.
545
+
546
+
547
+
548
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
549
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
550
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
551
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
552
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
553
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
554
+ THE SOFTWARE.
555
+ ```
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+
3
+ 'use strict';
4
+
5
+ var yargs = require('yargs');
6
+ var debug = require('debug')('http-mitm-proxy:bin');
7
+
8
+ var args = yargs
9
+ .alias('h', 'help')
10
+ .alias('h', '?')
11
+ .options('port', {
12
+ default: 80,
13
+ describe: 'HTTP Port.'
14
+ })
15
+ .alias('p', 'port')
16
+ .options('host', {
17
+ describe: 'HTTP Listen Interface.'
18
+ })
19
+ .argv;
20
+
21
+ if (args.help) {
22
+ yargs.showHelp();
23
+ return process.exit(-1);
24
+ }
25
+
26
+ var proxy = require('../lib/proxy')();
27
+ proxy.onError(function(ctx, err, errorKind) {
28
+ debug(errorKind, err);
29
+ });
30
+ proxy.listen(args, function(err) {
31
+ if (err) {
32
+ debug('Failed to start listening on port ' + args.port, err);
33
+ return process.exit(1);
34
+ }
35
+ debug('proxy listening on ' + args.port);
36
+ });