browsed 0.2.9 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +28 -28
  3. data/browsed.gemspec +3 -4
  4. data/lib/browsed.rb +1 -1
  5. data/lib/browsed/chrome.rb +2 -2
  6. data/lib/browsed/client.rb +2 -2
  7. data/lib/browsed/firefox.rb +2 -2
  8. data/lib/browsed/version.rb +1 -1
  9. metadata +13 -166
  10. data/lib/browsed/proxies/proxy-chain-server/node_modules/.bin/portastic +0 -1
  11. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/LICENSE +0 -21
  12. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/README.md +0 -57
  13. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/changelog.md +0 -1
  14. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.core.js +0 -3824
  15. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.core.min.js +0 -31
  16. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.js +0 -5666
  17. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.min.js +0 -31
  18. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/any.js +0 -21
  19. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/assert.js +0 -55
  20. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/async.js +0 -165
  21. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/bind.js +0 -67
  22. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/bluebird.js +0 -11
  23. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/call_get.js +0 -123
  24. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/cancel.js +0 -129
  25. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/catch_filter.js +0 -42
  26. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/context.js +0 -69
  27. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/debuggability.js +0 -934
  28. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/direct_resolve.js +0 -46
  29. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/each.js +0 -30
  30. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/errors.js +0 -116
  31. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/es5.js +0 -80
  32. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/filter.js +0 -12
  33. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/finally.js +0 -146
  34. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/generators.js +0 -223
  35. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/join.js +0 -168
  36. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/map.js +0 -168
  37. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/method.js +0 -55
  38. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/nodeback.js +0 -51
  39. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/nodeify.js +0 -58
  40. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promise.js +0 -789
  41. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promise_array.js +0 -185
  42. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promisify.js +0 -314
  43. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/props.js +0 -118
  44. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/queue.js +0 -73
  45. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/race.js +0 -49
  46. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/reduce.js +0 -172
  47. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/schedule.js +0 -62
  48. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/settle.js +0 -43
  49. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/some.js +0 -148
  50. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/synchronous_inspection.js +0 -103
  51. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/thenables.js +0 -86
  52. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/timers.js +0 -93
  53. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/using.js +0 -226
  54. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/util.js +0 -389
  55. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/package.json +0 -102
  56. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/CHANGELOG.md +0 -408
  57. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/LICENSE +0 -22
  58. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/Readme.md +0 -428
  59. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/index.js +0 -1224
  60. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/package.json +0 -70
  61. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/typings/index.d.ts +0 -310
  62. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.coveralls.yml +0 -1
  63. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.eslintrc +0 -11
  64. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.npmignore +0 -9
  65. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.travis.yml +0 -14
  66. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/CHANGELOG.md +0 -362
  67. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/LICENSE +0 -19
  68. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/Makefile +0 -50
  69. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/README.md +0 -312
  70. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/component.json +0 -19
  71. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/karma.conf.js +0 -70
  72. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/node.js +0 -1
  73. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/package.json +0 -88
  74. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/browser.js +0 -185
  75. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/debug.js +0 -202
  76. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/index.js +0 -10
  77. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/inspector-log.js +0 -15
  78. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/node.js +0 -248
  79. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/index.js +0 -152
  80. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/license.md +0 -21
  81. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/package.json +0 -69
  82. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/readme.md +0 -51
  83. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/LICENSE +0 -13
  84. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/README.md +0 -148
  85. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/bin/portastic +0 -65
  86. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/history.md +0 -7
  87. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/index.js +0 -4
  88. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/lib/monitor.js +0 -59
  89. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/lib/portastic.js +0 -167
  90. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/LICENSE +0 -21
  91. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/README.md +0 -677
  92. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/changelog.md +0 -1730
  93. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/browser/bluebird.js +0 -4892
  94. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/browser/bluebird.min.js +0 -31
  95. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/any.js +0 -21
  96. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/assert.js +0 -55
  97. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/async.js +0 -150
  98. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/bind.js +0 -72
  99. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/bluebird.js +0 -11
  100. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/call_get.js +0 -123
  101. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/cancel.js +0 -48
  102. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/captured_trace.js +0 -493
  103. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/catch_filter.js +0 -66
  104. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/context.js +0 -38
  105. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/debuggability.js +0 -162
  106. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/direct_resolve.js +0 -63
  107. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/each.js +0 -12
  108. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/errors.js +0 -111
  109. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/es5.js +0 -80
  110. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/filter.js +0 -12
  111. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/finally.js +0 -98
  112. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/generators.js +0 -136
  113. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/join.js +0 -107
  114. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/map.js +0 -133
  115. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/method.js +0 -44
  116. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/nodeify.js +0 -59
  117. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/progress.js +0 -76
  118. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise.js +0 -759
  119. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise_array.js +0 -142
  120. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise_resolver.js +0 -123
  121. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promisify.js +0 -307
  122. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/props.js +0 -79
  123. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/queue.js +0 -90
  124. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/race.js +0 -47
  125. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/reduce.js +0 -148
  126. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/schedule.js +0 -35
  127. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/settle.js +0 -40
  128. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/some.js +0 -125
  129. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/synchronous_inspection.js +0 -94
  130. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/thenables.js +0 -84
  131. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/timers.js +0 -64
  132. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/using.js +0 -213
  133. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/util.js +0 -321
  134. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/package.json +0 -103
  135. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/package.json +0 -69
  136. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/CHANGELOG.md +0 -109
  137. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/LICENSE +0 -201
  138. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/README.md +0 -278
  139. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/anonymize_proxy.js +0 -100
  140. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_base.js +0 -319
  141. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_custom_response.js +0 -96
  142. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_forward.js +0 -173
  143. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_chain.js +0 -132
  144. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_direct.js +0 -89
  145. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_tcp_chain.js +0 -271
  146. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/index.js +0 -26
  147. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/run_locally.js +0 -66
  148. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/server.js +0 -595
  149. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/tcp_tunnel.js +0 -138
  150. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/testing_tcp_service.js +0 -37
  151. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/tools.js +0 -220
  152. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/package.json +0 -104
  153. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/LICENSE +0 -23
  154. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/README.md +0 -28
  155. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/package.json +0 -81
  156. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore-min.js +0 -5
  157. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore-min.js.map +0 -1
  158. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore.js +0 -1692
  159. data/lib/browsed/proxies/proxy-chain-server/package-lock.json +0 -63
  160. data/lib/browsed/proxies/proxy-chain-server/package.json +0 -15
  161. data/lib/browsed/proxies/proxy-chain-server/server.js +0 -25
  162. data/lib/browsed/proxies/proxy_chain.rb +0 -39
@@ -1,100 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.closeAnonymizedProxy = exports.anonymizeProxy = undefined;
7
-
8
- var _bluebird = require('bluebird');
9
-
10
- var _bluebird2 = _interopRequireDefault(_bluebird);
11
-
12
- var _server = require('./server');
13
-
14
- var _tools = require('./tools');
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- // Dictionary, key is value returned from anonymizeProxy(), value is Server instance.
19
- var anonymizedProxyUrlToServer = {};
20
-
21
- /**
22
- * Parses and validates a HTTP proxy URL. If the proxy requires authentication, then the function
23
- * starts an open local proxy server that forwards to the upstream proxy.
24
- * @param proxyUrl
25
- * @param callback Optional callback that receives the anonymous proxy URL
26
- * @return If no callback was supplied, returns a promise that resolves to a String with
27
- * anonymous proxy URL or the original URL if it was already anonymous.
28
- */
29
- var anonymizeProxy = exports.anonymizeProxy = function anonymizeProxy(proxyUrl, callback) {
30
- var parsedProxyUrl = (0, _tools.parseUrl)(proxyUrl);
31
- if (!parsedProxyUrl.host || !parsedProxyUrl.port) {
32
- throw new Error('Invalid "proxyUrl" option: the URL must contain both hostname and port.');
33
- }
34
- if (parsedProxyUrl.scheme !== 'http') {
35
- throw new Error('Invalid "proxyUrl" option: only HTTP proxies are currently supported.');
36
- }
37
-
38
- // If upstream proxy requires no password, return it directly
39
- if (!parsedProxyUrl.username && !parsedProxyUrl.password) {
40
- return _bluebird2.default.resolve(proxyUrl).nodeify(callback);
41
- }
42
-
43
- var port = void 0;
44
- var server = void 0;
45
-
46
- var startServer = function startServer(maxRecursion) {
47
- return _bluebird2.default.resolve().then(function () {
48
- return (0, _tools.findFreePort)();
49
- }).then(function (result) {
50
- port = result;
51
- server = new _server.Server({
52
- // verbose: true,
53
- port: port,
54
- prepareRequestFunction: function prepareRequestFunction() {
55
- return {
56
- requestAuthentication: false,
57
- upstreamProxyUrl: proxyUrl
58
- };
59
- }
60
- });
61
-
62
- return server.listen();
63
- }).catch(function (err) {
64
- // It might happen that the port was taken in the meantime,
65
- // in which case retry the search
66
- if (err.code === 'EADDRINUSE' && maxRecursion > 0) {
67
- return startServer(maxRecursion - 1);
68
- }
69
- throw err;
70
- });
71
- };
72
-
73
- return startServer(_tools.PORT_SELECTION_CONFIG.RETRY_COUNT).then(function () {
74
- var url = 'http://127.0.0.1:' + port;
75
- anonymizedProxyUrlToServer[url] = server;
76
- return url;
77
- }).nodeify(callback);
78
- };
79
-
80
- /**
81
- * Closes anonymous proxy previously started by `anonymizeProxy()`.
82
- * If proxy was not found or was already closed, the function has no effect
83
- * and its result if `false`. Otherwise the result is `true`.
84
- * @param anonymizedProxyUrl
85
- * @param closeConnections If true, pending proxy connections are forcibly closed.
86
- * @param callback Optional callback
87
- * @returns Returns a promise if no callback was supplied
88
- */
89
- var closeAnonymizedProxy = exports.closeAnonymizedProxy = function closeAnonymizedProxy(anonymizedProxyUrl, closeConnections, callback) {
90
- var server = anonymizedProxyUrlToServer[anonymizedProxyUrl];
91
- if (!server) {
92
- return _bluebird2.default.resolve(false).nodeify(callback);
93
- }
94
-
95
- delete anonymizedProxyUrlToServer[anonymizedProxyUrl];
96
-
97
- return server.close(closeConnections).then(function () {
98
- return true;
99
- }).nodeify(callback);
100
- };
@@ -1,319 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8
-
9
- var _http = require('http');
10
-
11
- var _http2 = _interopRequireDefault(_http);
12
-
13
- var _events = require('events');
14
-
15
- var _events2 = _interopRequireDefault(_events);
16
-
17
- var _server = require('./server');
18
-
19
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
-
21
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
22
-
23
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
24
-
25
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
26
-
27
- /* globals Buffer */
28
-
29
- /**
30
- * Base class for proxy connection handlers. It emits the `destroyed` event
31
- * when the handler is no longer used.
32
- */
33
- var HandlerBase = function (_EventEmitter) {
34
- _inherits(HandlerBase, _EventEmitter);
35
-
36
- function HandlerBase(_ref) {
37
- var server = _ref.server,
38
- id = _ref.id,
39
- srcRequest = _ref.srcRequest,
40
- srcHead = _ref.srcHead,
41
- srcResponse = _ref.srcResponse,
42
- trgParsed = _ref.trgParsed,
43
- upstreamProxyUrlParsed = _ref.upstreamProxyUrlParsed;
44
-
45
- _classCallCheck(this, HandlerBase);
46
-
47
- var _this = _possibleConstructorReturn(this, (HandlerBase.__proto__ || Object.getPrototypeOf(HandlerBase)).call(this));
48
-
49
- if (!server) throw new Error('The "server" option is required');
50
- if (!id) throw new Error('The "id" option is required');
51
- if (!srcRequest) throw new Error('The "srcRequest" option is required');
52
- if (!trgParsed.hostname) throw new Error('The "trgParsed.hostname" option is required');
53
-
54
- _this.server = server;
55
- _this.id = id;
56
-
57
- _this.srcRequest = srcRequest;
58
- _this.srcHead = srcHead;
59
- _this.srcResponse = srcResponse;
60
- _this.srcSocket = srcRequest.socket;
61
-
62
- _this.trgRequest = null;
63
- _this.trgSocket = null;
64
- _this.trgParsed = trgParsed;
65
- _this.trgParsed.port = _this.trgParsed.port || DEFAULT_TARGET_PORT;
66
-
67
- // Indicates that source socket might have received some data already
68
- _this.srcGotResponse = false;
69
-
70
- _this.isClosed = false;
71
-
72
- _this.upstreamProxyUrlParsed = upstreamProxyUrlParsed;
73
-
74
- // Create ServerResponse for the client HTTP request if it doesn't exist
75
- // NOTE: This is undocumented API, it might break in the future
76
- if (!_this.srcResponse) {
77
- _this.srcResponse = new _http2.default.ServerResponse(srcRequest);
78
- _this.srcResponse.shouldKeepAlive = false;
79
- _this.srcResponse.chunkedEncoding = false;
80
- _this.srcResponse.useChunkedEncodingByDefault = false;
81
- _this.srcResponse.assignSocket(_this.srcSocket);
82
- }
83
-
84
- // Bind all event handlers to this instance
85
- _this.bindHandlersToThis(['onSrcResponseFinish', 'onSrcSocketClose', 'onSrcSocketEnd', 'onSrcSocketError', 'onTrgSocket', 'onTrgSocketClose', 'onTrgSocketEnd', 'onTrgSocketError']);
86
-
87
- // Called for the ServerResponse's "finish" event
88
- // Normally, Node's "http" module has a "finish" event listener that would
89
- // take care of closing the socket once the HTTP response has completed, but
90
- // since we're making this ServerResponse instance manually, that event handler
91
- // never gets hooked up, so we must manually close the socket...
92
- _this.srcResponse.once('finish', _this.onSrcResponseFinish);
93
-
94
- _this.srcSocket.once('close', _this.onSrcSocketClose);
95
- _this.srcSocket.once('end', _this.onSrcSocketEnd);
96
- _this.srcSocket.once('error', _this.onSrcSocketError);
97
- return _this;
98
- }
99
-
100
- _createClass(HandlerBase, [{
101
- key: 'bindHandlersToThis',
102
- value: function bindHandlersToThis(handlerNames) {
103
- var _this2 = this;
104
-
105
- handlerNames.forEach(function (evt) {
106
- _this2[evt] = _this2[evt].bind(_this2);
107
- });
108
- }
109
- }, {
110
- key: 'log',
111
- value: function log(str) {
112
- this.server.log(this.id, str);
113
- }
114
-
115
- // Abstract method, needs to be overridden
116
-
117
- }, {
118
- key: 'run',
119
- value: function run() {} // eslint-disable-line
120
-
121
- // If the client closes the connection prematurely,
122
- // then immediately destroy the upstream socket, there's nothing we can do with it
123
-
124
- }, {
125
- key: 'onSrcSocketClose',
126
- value: function onSrcSocketClose() {
127
- if (this.isClosed) return;
128
- this.log('Source socket closed');
129
- this.close();
130
- }
131
- }, {
132
- key: 'onSrcSocketEnd',
133
- value: function onSrcSocketEnd() {
134
- if (this.isClosed) return;
135
- this.log('Source socket ended');
136
- this.close();
137
- }
138
- }, {
139
- key: 'onSrcSocketError',
140
- value: function onSrcSocketError(err) {
141
- if (this.isClosed) return;
142
- this.log('Source socket failed: ' + (err.stack || err));
143
- this.close();
144
- }
145
- }, {
146
- key: 'onSrcResponseFinish',
147
- value: function onSrcResponseFinish() {
148
- if (this.isClosed) return;
149
- this.log('Source response finished, ending source socket');
150
- // NOTE: We cannot destroy the socket, since there might be pending data that wouldn't be delivered!
151
- // This code is inspired by resOnFinish() in _http_server.js in Node.js code base.
152
- if (typeof this.srcSocket.destroySoon === 'function') {
153
- this.srcSocket.destroySoon();
154
- } else {
155
- this.srcSocket.end();
156
- }
157
- }
158
- }, {
159
- key: 'onTrgSocket',
160
- value: function onTrgSocket(socket) {
161
- if (this.isClosed) return;
162
- this.log('Target socket assigned');
163
-
164
- this.trgSocket = socket;
165
-
166
- socket.once('close', this.onTrgSocketClose);
167
- socket.once('end', this.onTrgSocketEnd);
168
- socket.once('error', this.onTrgSocketError);
169
- }
170
-
171
- // Once target socket closes, we need to give time
172
- // to source socket to receive pending data, so we only call end()
173
-
174
- }, {
175
- key: 'onTrgSocketClose',
176
- value: function onTrgSocketClose() {
177
- if (this.isClosed) return;
178
- this.log('Target socket closed');
179
- // If socket is closed here instead of response, phantomjs does not properly parse the response as http response.
180
- if (this.srcResponse) {
181
- this.srcResponse.end();
182
- } else if (this.srcSocket) {
183
- // Handler tunnel chain does not use srcResponse, but needs to close srcSocket
184
- this.srcSocket.end();
185
- }
186
- }
187
- }, {
188
- key: 'onTrgSocketEnd',
189
- value: function onTrgSocketEnd() {
190
- if (this.isClosed) return;
191
- this.log('Target socket ended');
192
- // If socket is closed here instead of response, phantomjs does not properly parse the response as http response.
193
- if (this.srcResponse) {
194
- this.srcResponse.end();
195
- } else if (this.srcSocket) {
196
- // Handler tunnel chain does not use srcResponse, but needs to close srcSocket
197
- this.srcSocket.end();
198
- }
199
- }
200
- }, {
201
- key: 'onTrgSocketError',
202
- value: function onTrgSocketError(err) {
203
- if (this.isClosed) return;
204
- this.log('Target socket failed: ' + (err.stack || err));
205
- this.fail(err);
206
- }
207
-
208
- /**
209
- * Checks whether response from upstream proxy is 407 Proxy Authentication Required
210
- * and if so, responds 502 Bad Gateway to client.
211
- * @param response
212
- * @return {boolean}
213
- */
214
-
215
- }, {
216
- key: 'checkUpstreamProxy407',
217
- value: function checkUpstreamProxy407(response) {
218
- if (this.upstreamProxyUrlParsed && response.statusCode === 407) {
219
- this.fail(new _server.RequestError('Invalid credentials provided for the upstream proxy.', 502));
220
- return true;
221
- }
222
- return false;
223
- }
224
- }, {
225
- key: 'fail',
226
- value: function fail(err) {
227
- if (this.srcGotResponse) {
228
- this.log('Source already received a response, just destroying the socket...');
229
- this.close();
230
- } else if (err.statusCode) {
231
- // Error is RequestError with HTTP status code
232
- this.log(err + ', responding with custom status code ' + err.statusCode + ' to client');
233
- this.srcResponse.writeHead(err.statusCode);
234
- this.srcResponse.end('' + err.message);
235
- } else if (err.code === 'ENOTFOUND' && !this.upstreamProxyUrlParsed) {
236
- this.log('Target server not found, sending 404 to client');
237
- this.srcResponse.writeHead(404);
238
- this.srcResponse.end('Target server not found');
239
- } else if (err.code === 'ENOTFOUND' && this.upstreamProxyUrlParsed) {
240
- this.log('Upstream proxy not found, sending 502 to client');
241
- this.srcResponse.writeHead(502);
242
- this.srcResponse.end('Upstream proxy was not found');
243
- } else if (err.code === 'ECONNREFUSED') {
244
- this.log('Upstream proxy refused connection, sending 502 to client');
245
- this.srcResponse.writeHead(502);
246
- this.srcResponse.end('Upstream proxy refused connection');
247
- } else if (err.code === 'ETIMEDOUT') {
248
- this.log('Connection timed out, sending 502 to client');
249
- this.srcResponse.writeHead(502);
250
- this.srcResponse.end('Connection to upstream proxy timed out');
251
- } else if (err.code === 'ECONNRESET') {
252
- this.log('Connection lost, sending 502 to client');
253
- this.srcResponse.writeHead(502);
254
- this.srcResponse.end('Connection lost');
255
- } else if (err.code === 'EPIPE') {
256
- this.log('Socket closed before write, sending 502 to client');
257
- this.srcResponse.writeHead(502);
258
- this.srcResponse.end('Connection interrupted');
259
- } else {
260
- this.log('Unknown error, sending 500 to client');
261
- this.srcResponse.writeHead(500);
262
- this.srcResponse.end('Internal error in proxy server');
263
- }
264
- }
265
- }, {
266
- key: 'getStats',
267
- value: function getStats() {
268
- return {
269
- srcTxBytes: this.srcSocket ? this.srcSocket.bytesWritten : null,
270
- srcRxBytes: this.srcSocket ? this.srcSocket.bytesRead : null,
271
- trgTxBytes: this.trgSocket ? this.trgSocket.bytesWritten : null,
272
- trgRxBytes: this.trgSocket ? this.trgSocket.bytesRead : null
273
- };
274
- }
275
-
276
- /**
277
- * Detaches all listeners and destroys all sockets.
278
- */
279
-
280
- }, {
281
- key: 'close',
282
- value: function close() {
283
- if (!this.isClosed) {
284
- this.log('Closing handler');
285
-
286
- // Save stats before sockets are destroyed
287
- var stats = this.getStats();
288
-
289
- if (this.srcRequest) {
290
- this.srcRequest.destroy();
291
- this.srcRequest = null;
292
- }
293
-
294
- if (this.srcSocket) {
295
- this.srcSocket.destroy();
296
- this.srcSocket = null;
297
- }
298
-
299
- if (this.trgRequest) {
300
- this.trgRequest.abort();
301
- this.trgRequest = null;
302
- }
303
-
304
- if (this.trgSocket) {
305
- this.trgSocket.destroy();
306
- this.trgSocket = null;
307
- }
308
-
309
- this.isClosed = true;
310
-
311
- this.emit('close', { stats: stats });
312
- }
313
- }
314
- }]);
315
-
316
- return HandlerBase;
317
- }(_events2.default);
318
-
319
- exports.default = HandlerBase;
@@ -1,96 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8
-
9
- var _underscore = require('underscore');
10
-
11
- var _underscore2 = _interopRequireDefault(_underscore);
12
-
13
- var _bluebird = require('bluebird');
14
-
15
- var _bluebird2 = _interopRequireDefault(_bluebird);
16
-
17
- var _handler_base = require('./handler_base');
18
-
19
- var _handler_base2 = _interopRequireDefault(_handler_base);
20
-
21
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
-
23
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
24
-
25
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
26
-
27
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
28
-
29
- /**
30
- * Represents a proxied HTTP request for which the response is generated by custom user function.
31
- * This is useful e.g. when providing access to external APIs via HTTP proxy interface.
32
- */
33
- var HandlerCustomResponse = function (_HandlerBase) {
34
- _inherits(HandlerCustomResponse, _HandlerBase);
35
-
36
- function HandlerCustomResponse(options) {
37
- _classCallCheck(this, HandlerCustomResponse);
38
-
39
- var _this = _possibleConstructorReturn(this, (HandlerCustomResponse.__proto__ || Object.getPrototypeOf(HandlerCustomResponse)).call(this, options));
40
-
41
- _this.customResponseFunction = options.customResponseFunction;
42
- if (!_this.customResponseFunction) throw new Error('The "customResponseFunction" option is required');
43
- return _this;
44
- }
45
-
46
- _createClass(HandlerCustomResponse, [{
47
- key: 'run',
48
- value: function run() {
49
- var _this2 = this;
50
-
51
- var reqOpts = this.trgParsed;
52
- reqOpts.method = this.srcRequest.method;
53
- reqOpts.headers = {};
54
-
55
- _bluebird2.default.resolve().then(function () {
56
- return _this2.customResponseFunction();
57
- }).then(function (customResponse) {
58
- if (_this2.isClosed) return;
59
-
60
- if (!customResponse) {
61
- throw new Error('The user-provided "customResponseFunction" must return an object.');
62
- }
63
-
64
- var statusCode = customResponse.statusCode || 200;
65
- var length = customResponse.body ? customResponse.body.length : null;
66
-
67
- _this2.log('Received custom user response (' + statusCode + ', length: ' + length + ', encoding: ' + customResponse.encoding + ')');
68
-
69
- // Forward custom response to source
70
- _this2.srcResponse.statusCode = statusCode;
71
-
72
- _underscore2.default.each(customResponse.headers, function (value, key) {
73
- _this2.srcResponse.setHeader(key, value);
74
- });
75
-
76
- return new _bluebird2.default(function (resolve, reject) {
77
- _this2.srcGotResponse = true;
78
- _this2.srcResponse.end(customResponse.body, customResponse.encoding, function (err) {
79
- if (err) return reject(err);
80
- resolve();
81
- });
82
- });
83
- }).then(function () {
84
- _this2.log('Custom response sent to source');
85
- }).catch(function (err) {
86
- if (_this2.isClosed) return;
87
- _this2.log('Custom response function failed: ' + (err.stack || err));
88
- _this2.fail(err);
89
- });
90
- }
91
- }]);
92
-
93
- return HandlerCustomResponse;
94
- }(_handler_base2.default);
95
-
96
- exports.default = HandlerCustomResponse;