browsed 0.2.8 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) 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/browser.rb +2 -2
  6. data/lib/browsed/chrome.rb +2 -2
  7. data/lib/browsed/client.rb +4 -3
  8. data/lib/browsed/firefox.rb +2 -2
  9. data/lib/browsed/version.rb +1 -1
  10. metadata +13 -166
  11. data/lib/browsed/proxies/proxy-chain-server/node_modules/.bin/portastic +0 -1
  12. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/LICENSE +0 -21
  13. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/README.md +0 -57
  14. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/changelog.md +0 -1
  15. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.core.js +0 -3824
  16. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.core.min.js +0 -31
  17. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.js +0 -5666
  18. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.min.js +0 -31
  19. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/any.js +0 -21
  20. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/assert.js +0 -55
  21. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/async.js +0 -165
  22. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/bind.js +0 -67
  23. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/bluebird.js +0 -11
  24. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/call_get.js +0 -123
  25. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/cancel.js +0 -129
  26. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/catch_filter.js +0 -42
  27. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/context.js +0 -69
  28. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/debuggability.js +0 -934
  29. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/direct_resolve.js +0 -46
  30. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/each.js +0 -30
  31. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/errors.js +0 -116
  32. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/es5.js +0 -80
  33. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/filter.js +0 -12
  34. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/finally.js +0 -146
  35. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/generators.js +0 -223
  36. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/join.js +0 -168
  37. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/map.js +0 -168
  38. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/method.js +0 -55
  39. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/nodeback.js +0 -51
  40. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/nodeify.js +0 -58
  41. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promise.js +0 -789
  42. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promise_array.js +0 -185
  43. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promisify.js +0 -314
  44. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/props.js +0 -118
  45. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/queue.js +0 -73
  46. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/race.js +0 -49
  47. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/reduce.js +0 -172
  48. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/schedule.js +0 -62
  49. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/settle.js +0 -43
  50. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/some.js +0 -148
  51. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/synchronous_inspection.js +0 -103
  52. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/thenables.js +0 -86
  53. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/timers.js +0 -93
  54. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/using.js +0 -226
  55. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/util.js +0 -389
  56. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/package.json +0 -102
  57. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/CHANGELOG.md +0 -408
  58. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/LICENSE +0 -22
  59. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/Readme.md +0 -428
  60. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/index.js +0 -1224
  61. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/package.json +0 -70
  62. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/typings/index.d.ts +0 -310
  63. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.coveralls.yml +0 -1
  64. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.eslintrc +0 -11
  65. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.npmignore +0 -9
  66. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.travis.yml +0 -14
  67. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/CHANGELOG.md +0 -362
  68. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/LICENSE +0 -19
  69. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/Makefile +0 -50
  70. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/README.md +0 -312
  71. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/component.json +0 -19
  72. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/karma.conf.js +0 -70
  73. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/node.js +0 -1
  74. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/package.json +0 -88
  75. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/browser.js +0 -185
  76. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/debug.js +0 -202
  77. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/index.js +0 -10
  78. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/inspector-log.js +0 -15
  79. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/node.js +0 -248
  80. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/index.js +0 -152
  81. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/license.md +0 -21
  82. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/package.json +0 -69
  83. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/readme.md +0 -51
  84. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/LICENSE +0 -13
  85. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/README.md +0 -148
  86. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/bin/portastic +0 -65
  87. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/history.md +0 -7
  88. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/index.js +0 -4
  89. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/lib/monitor.js +0 -59
  90. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/lib/portastic.js +0 -167
  91. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/LICENSE +0 -21
  92. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/README.md +0 -677
  93. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/changelog.md +0 -1730
  94. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/browser/bluebird.js +0 -4892
  95. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/browser/bluebird.min.js +0 -31
  96. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/any.js +0 -21
  97. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/assert.js +0 -55
  98. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/async.js +0 -150
  99. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/bind.js +0 -72
  100. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/bluebird.js +0 -11
  101. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/call_get.js +0 -123
  102. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/cancel.js +0 -48
  103. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/captured_trace.js +0 -493
  104. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/catch_filter.js +0 -66
  105. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/context.js +0 -38
  106. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/debuggability.js +0 -162
  107. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/direct_resolve.js +0 -63
  108. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/each.js +0 -12
  109. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/errors.js +0 -111
  110. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/es5.js +0 -80
  111. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/filter.js +0 -12
  112. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/finally.js +0 -98
  113. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/generators.js +0 -136
  114. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/join.js +0 -107
  115. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/map.js +0 -133
  116. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/method.js +0 -44
  117. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/nodeify.js +0 -59
  118. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/progress.js +0 -76
  119. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise.js +0 -759
  120. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise_array.js +0 -142
  121. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise_resolver.js +0 -123
  122. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promisify.js +0 -307
  123. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/props.js +0 -79
  124. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/queue.js +0 -90
  125. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/race.js +0 -47
  126. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/reduce.js +0 -148
  127. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/schedule.js +0 -35
  128. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/settle.js +0 -40
  129. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/some.js +0 -125
  130. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/synchronous_inspection.js +0 -94
  131. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/thenables.js +0 -84
  132. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/timers.js +0 -64
  133. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/using.js +0 -213
  134. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/util.js +0 -321
  135. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/package.json +0 -103
  136. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/package.json +0 -69
  137. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/CHANGELOG.md +0 -109
  138. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/LICENSE +0 -201
  139. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/README.md +0 -278
  140. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/anonymize_proxy.js +0 -100
  141. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_base.js +0 -319
  142. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_custom_response.js +0 -96
  143. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_forward.js +0 -173
  144. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_chain.js +0 -132
  145. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_direct.js +0 -89
  146. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_tcp_chain.js +0 -271
  147. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/index.js +0 -26
  148. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/run_locally.js +0 -66
  149. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/server.js +0 -595
  150. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/tcp_tunnel.js +0 -138
  151. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/testing_tcp_service.js +0 -37
  152. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/tools.js +0 -220
  153. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/package.json +0 -104
  154. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/LICENSE +0 -23
  155. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/README.md +0 -28
  156. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/package.json +0 -81
  157. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore-min.js +0 -5
  158. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore-min.js.map +0 -1
  159. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore.js +0 -1692
  160. data/lib/browsed/proxies/proxy-chain-server/package-lock.json +0 -63
  161. data/lib/browsed/proxies/proxy-chain-server/package.json +0 -15
  162. data/lib/browsed/proxies/proxy-chain-server/server.js +0 -25
  163. data/lib/browsed/proxies/proxy_chain.rb +0 -39
@@ -1,173 +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 _tools = require('./tools');
14
-
15
- var _handler_base = require('./handler_base');
16
-
17
- var _handler_base2 = _interopRequireDefault(_handler_base);
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
- /**
28
- * Represents a proxied request to a HTTP server, either direct or via another upstream proxy.
29
- */
30
- var HandlerForward = function (_HandlerBase) {
31
- _inherits(HandlerForward, _HandlerBase);
32
-
33
- function HandlerForward(options) {
34
- _classCallCheck(this, HandlerForward);
35
-
36
- var _this = _possibleConstructorReturn(this, (HandlerForward.__proto__ || Object.getPrototypeOf(HandlerForward)).call(this, options));
37
-
38
- _this.bindHandlersToThis(['onTrgResponse', 'onTrgError']);
39
- return _this;
40
- }
41
-
42
- _createClass(HandlerForward, [{
43
- key: 'run',
44
- value: function run() {
45
- var reqOpts = this.trgParsed;
46
- reqOpts.method = this.srcRequest.method;
47
- reqOpts.headers = {};
48
-
49
- // setup outbound proxy request HTTP headers
50
- // TODO: var hasXForwardedFor = false;
51
- // var hasVia = false;
52
- // var via = '1.1 ' + hostname + ' (proxy/' + version + ')';
53
-
54
- for (var i = 0; i < this.srcRequest.rawHeaders.length; i += 2) {
55
- var headerName = this.srcRequest.rawHeaders[i];
56
- var headerValue = this.srcRequest.rawHeaders[i + 1];
57
-
58
- if (headerName === 'Connection' && headerValue === 'keep-alive') {
59
- // Keep the "Connection: keep-alive" header, to reduce the chance that the server
60
- // will detect we're not a browser and also to improve performance
61
- } else if ((0, _tools.isHopByHopHeader)(headerName)) {
62
- continue;
63
- } else if ((0, _tools.isInvalidHeader)(headerName, headerValue)) {
64
- continue;
65
- }
66
-
67
- /*
68
- if (!hasXForwardedFor && 'x-forwarded-for' === keyLower) {
69
- // append to existing "X-Forwarded-For" header
70
- // http://en.wikipedia.org/wiki/X-Forwarded-For
71
- hasXForwardedFor = true;
72
- value += ', ' + socket.remoteAddress;
73
- debug.proxyRequest('appending to existing "%s" header: "%s"', key, value);
74
- }
75
- if (!hasVia && 'via' === keyLower) {
76
- // append to existing "Via" header
77
- hasVia = true;
78
- value += ', ' + via;
79
- debug.proxyRequest('appending to existing "%s" header: "%s"', key, value);
80
- }
81
- */
82
-
83
- (0, _tools.addHeader)(reqOpts.headers, headerName, headerValue);
84
- }
85
-
86
- /*
87
- // add "X-Forwarded-For" header if it's still not here by now
88
- // http://en.wikipedia.org/wiki/X-Forwarded-For
89
- if (!hasXForwardedFor) {
90
- headers['X-Forwarded-For'] = socket.remoteAddress;
91
- debug.proxyRequest('adding new "X-Forwarded-For" header: "%s"', headers['X-Forwarded-For']);
92
- }
93
- // add "Via" header if still not set by now
94
- if (!hasVia) {
95
- headers.Via = via;
96
- debug.proxyRequest('adding new "Via" header: "%s"', headers.Via);
97
- }
98
- // custom `http.Agent` support, set `server.agent`
99
- var agent = server.agent;
100
- if (null != agent) {
101
- debug.proxyRequest('setting custom `http.Agent` option for proxy request: %s', agent);
102
- parsed.agent = agent;
103
- agent = null;
104
- }
105
- */
106
-
107
- // If desired, send the request via proxy
108
- if (this.upstreamProxyUrlParsed) {
109
- reqOpts.host = this.upstreamProxyUrlParsed.hostname;
110
- reqOpts.hostname = reqOpts.host;
111
- reqOpts.port = this.upstreamProxyUrlParsed.port;
112
-
113
- // HTTP requests to proxy contain the full URL in path, for example:
114
- // "GET http://www.example.com HTTP/1.1\r\n"
115
- // So we need to replicate it here
116
- reqOpts.path = this.srcRequest.url;
117
-
118
- (0, _tools.maybeAddProxyAuthorizationHeader)(this.upstreamProxyUrlParsed, reqOpts.headers);
119
-
120
- this.log('Connecting to upstream proxy ' + reqOpts.host + ':' + reqOpts.port);
121
- } else {
122
- this.log('Connecting to target ' + reqOpts.host);
123
- }
124
-
125
- // console.dir(requestOptions);
126
-
127
- this.trgRequest = _http2.default.request(reqOpts);
128
- this.trgRequest.on('response', this.onTrgResponse);
129
- this.trgRequest.on('error', this.onTrgError);
130
- this.trgRequest.on('socket', this.onTrgSocket);
131
-
132
- // this.srcRequest.pipe(tee('to trg')).pipe(this.trgRequest);
133
- this.srcRequest.pipe(this.trgRequest);
134
- }
135
- }, {
136
- key: 'onTrgResponse',
137
- value: function onTrgResponse(response) {
138
- if (this.isClosed) return;
139
- this.log('Received response from target (' + response.statusCode + ')');
140
- // console.dir(response);
141
-
142
- if (this.checkUpstreamProxy407(response)) return;
143
-
144
- this.srcGotResponse = true;
145
-
146
- // Prepare response headers
147
- var headers = {};
148
- for (var i = 0; i < response.rawHeaders.length; i += 2) {
149
- var name = response.rawHeaders[i];
150
- var value = response.rawHeaders[i + 1];
151
-
152
- if ((0, _tools.isHopByHopHeader)(name)) continue;
153
- if ((0, _tools.isInvalidHeader)(name, value)) continue;
154
-
155
- (0, _tools.addHeader)(headers, name, value);
156
- }
157
-
158
- this.srcResponse.writeHead(response.statusCode, headers);
159
- response.pipe(this.srcResponse);
160
- }
161
- }, {
162
- key: 'onTrgError',
163
- value: function onTrgError(err) {
164
- if (this.isClosed) return;
165
- this.log('Target socket failed: ' + (err.stack || err));
166
- this.fail(err);
167
- }
168
- }]);
169
-
170
- return HandlerForward;
171
- }(_handler_base2.default);
172
-
173
- exports.default = HandlerForward;
@@ -1,132 +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 _handler_base = require('./handler_base');
14
-
15
- var _handler_base2 = _interopRequireDefault(_handler_base);
16
-
17
- var _tools = require('./tools');
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
- // import { tee } from './tools';
28
-
29
- /* globals Buffer */
30
-
31
- /**
32
- * Represents a connection from source client to an external proxy using HTTP CONNECT tunnel.
33
- */
34
- var HandlerTunnelChain = function (_HandlerBase) {
35
- _inherits(HandlerTunnelChain, _HandlerBase);
36
-
37
- function HandlerTunnelChain(options) {
38
- _classCallCheck(this, HandlerTunnelChain);
39
-
40
- var _this = _possibleConstructorReturn(this, (HandlerTunnelChain.__proto__ || Object.getPrototypeOf(HandlerTunnelChain)).call(this, options));
41
-
42
- if (!_this.upstreamProxyUrlParsed) throw new Error('The "upstreamProxyUrlParsed" option is required');
43
-
44
- _this.bindHandlersToThis(['onTrgRequestConnect', 'onTrgRequestAbort', 'onTrgRequestError']);
45
- return _this;
46
- }
47
-
48
- _createClass(HandlerTunnelChain, [{
49
- key: 'run',
50
- value: function run() {
51
- this.log('Connecting to upstream proxy...');
52
-
53
- var targetHost = this.trgParsed.hostname + ':' + this.trgParsed.port;
54
-
55
- var options = {
56
- method: 'CONNECT',
57
- hostname: this.upstreamProxyUrlParsed.hostname,
58
- port: this.upstreamProxyUrlParsed.port,
59
- path: targetHost,
60
- headers: {
61
- Host: targetHost
62
- }
63
- };
64
-
65
- (0, _tools.maybeAddProxyAuthorizationHeader)(this.upstreamProxyUrlParsed, options.headers);
66
-
67
- this.trgRequest = _http2.default.request(options);
68
-
69
- this.trgRequest.once('connect', this.onTrgRequestConnect);
70
- this.trgRequest.once('abort', this.onTrgRequestAbort);
71
- this.trgRequest.once('error', this.onTrgRequestError);
72
- this.trgRequest.on('socket', this.onTrgSocket);
73
-
74
- // Send the data
75
- this.trgRequest.end();
76
- }
77
- }, {
78
- key: 'onTrgRequestConnect',
79
- value: function onTrgRequestConnect(response, socket, head) {
80
- if (this.isClosed) return;
81
- this.log('Connected to upstream proxy');
82
-
83
- if (this.checkUpstreamProxy407(response)) return;
84
-
85
- this.srcGotResponse = true;
86
- this.srcResponse.removeListener('finish', this.onSrcResponseFinish);
87
- this.srcResponse.writeHead(200, 'Connection established');
88
-
89
- // HACK: force a flush of the HTTP header. This is to ensure 'head' is empty to avoid
90
- // assert at https://github.com/request/tunnel-agent/blob/master/index.js#L160
91
- // See also https://github.com/nodejs/node/blob/master/lib/_http_outgoing.js#L217
92
- this.srcResponse._send('');
93
-
94
- // relinquish control of the `socket` from the ServerResponse instance
95
- this.srcResponse.detachSocket(this.srcSocket);
96
-
97
- // nullify the ServerResponse object, so that it can be cleaned
98
- // up before this socket proxying is completed
99
- this.srcResponse = null;
100
-
101
- // Forward pre-parsed parts of the first packets (if any)
102
- if (head && head.length > 0) {
103
- this.srcSocket.write(head);
104
- }
105
- if (this.srcHead && this.srcHead.length > 0) {
106
- this.trgSocket.write(this.srcHead);
107
- }
108
-
109
- // Setup bi-directional tunnel
110
- this.trgSocket.pipe(this.srcSocket);
111
- this.srcSocket.pipe(this.trgSocket);
112
- }
113
- }, {
114
- key: 'onTrgRequestAbort',
115
- value: function onTrgRequestAbort() {
116
- if (this.isClosed) return;
117
- this.log('Target aborted');
118
- this.close();
119
- }
120
- }, {
121
- key: 'onTrgRequestError',
122
- value: function onTrgRequestError(err) {
123
- if (this.isClosed) return;
124
- this.log('Target request failed: ' + (err.stack || err));
125
- this.fail(err);
126
- }
127
- }]);
128
-
129
- return HandlerTunnelChain;
130
- }(_handler_base2.default);
131
-
132
- exports.default = HandlerTunnelChain;
@@ -1,89 +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 _net = require('net');
10
-
11
- var _net2 = _interopRequireDefault(_net);
12
-
13
- var _handler_base = require('./handler_base');
14
-
15
- var _handler_base2 = _interopRequireDefault(_handler_base);
16
-
17
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
-
19
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
20
-
21
- 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; }
22
-
23
- 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; }
24
-
25
- /**
26
- * Represents a proxied connection from source to the target HTTPS server.
27
- */
28
- var HandlerTunnelDirect = function (_HandlerBase) {
29
- _inherits(HandlerTunnelDirect, _HandlerBase);
30
-
31
- function HandlerTunnelDirect(options) {
32
- _classCallCheck(this, HandlerTunnelDirect);
33
-
34
- var _this = _possibleConstructorReturn(this, (HandlerTunnelDirect.__proto__ || Object.getPrototypeOf(HandlerTunnelDirect)).call(this, options));
35
-
36
- _this.bindHandlersToThis(['onTrgSocketConnect']);
37
- return _this;
38
- }
39
-
40
- _createClass(HandlerTunnelDirect, [{
41
- key: 'run',
42
- value: function run() {
43
- this.log('Connecting to target ' + this.trgParsed.hostname + ':' + this.trgParsed.port);
44
-
45
- var socket = _net2.default.createConnection(this.trgParsed.port, this.trgParsed.hostname);
46
- socket.once('connect', this.onTrgSocketConnect);
47
-
48
- this.onTrgSocket(socket);
49
- }
50
- }, {
51
- key: 'onTrgSocketConnect',
52
- value: function onTrgSocketConnect(response, socket, head) {
53
- if (this.isClosed) return;
54
- this.log('Connected');
55
-
56
- this.srcGotResponse = true;
57
-
58
- this.srcResponse.removeListener('finish', this.onSrcResponseFinish);
59
- this.srcResponse.writeHead(200, 'Connection established');
60
-
61
- // HACK: force a flush of the HTTP header. This is to ensure 'head' is empty to avoid
62
- // assert at https://github.com/request/tunnel-agent/blob/master/index.js#L160
63
- // See also https://github.com/nodejs/node/blob/master/lib/_http_outgoing.js#L217
64
- this.srcResponse._send('');
65
-
66
- // Relinquish control of the socket from the ServerResponse instance
67
- this.srcResponse.detachSocket(this.srcSocket);
68
-
69
- // ServerResponse is no longer needed
70
- this.srcResponse = null;
71
-
72
- // Forward pre-parsed parts of the first packets (if any)
73
- if (head && head.length > 0) {
74
- this.srcSocket.write(head);
75
- }
76
- if (this.srcHead && this.srcHead.length > 0) {
77
- this.trgSocket.write(this.srcHead);
78
- }
79
-
80
- // Setup bi-directional tunnel
81
- this.trgSocket.pipe(this.srcSocket);
82
- this.srcSocket.pipe(this.trgSocket);
83
- }
84
- }]);
85
-
86
- return HandlerTunnelDirect;
87
- }(_handler_base2.default);
88
-
89
- exports.default = HandlerTunnelDirect;
@@ -1,271 +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 _tools = require('./tools');
14
-
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
-
17
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
-
19
- /* globals Buffer */
20
-
21
- // TODO: please rename this class to something else than "Handler", it makes it look like the class inherits from HandlerBase, which it doesn't
22
-
23
- /**
24
- * Represents a connection from source client to an external proxy using HTTP CONNECT tunnel, allows TCP connection.
25
- */
26
- var HandlerTunnelTcpChain = function () {
27
- function HandlerTunnelTcpChain(_ref) {
28
- var srcSocket = _ref.srcSocket,
29
- trgParsed = _ref.trgParsed,
30
- upstreamProxyUrlParsed = _ref.upstreamProxyUrlParsed,
31
- log = _ref.log;
32
-
33
- _classCallCheck(this, HandlerTunnelTcpChain);
34
-
35
- this.log = log;
36
-
37
- // Bind all event handlers to this instance
38
- this.bindHandlersToThis(['onSrcSocketClose', 'onSrcSocketEnd', 'onSrcSocketError', 'onTrgSocket', 'onTrgSocketClose', 'onTrgSocketEnd', 'onTrgSocketError', 'onTrgRequestConnect', 'onTrgRequestAbort', 'onTrgRequestError']);
39
-
40
- if (!trgParsed.hostname) throw new Error('The "trgParsed.hostname" option is required');
41
- if (!trgParsed.port) throw new Error('The "trgParsed.port" option is required');
42
-
43
- this.trgRequest = null;
44
- this.trgSocket = null;
45
- this.trgParsed = trgParsed;
46
- this.trgParsed.port = this.trgParsed.port || DEFAULT_TARGET_PORT;
47
-
48
- this.srcSocket = srcSocket;
49
- this.srcSocket.once('close', this.onSrcSocketClose);
50
- this.srcSocket.once('end', this.onSrcSocketEnd);
51
- this.srcSocket.once('error', this.onSrcSocketError);
52
-
53
- this.upstreamProxyUrlParsed = upstreamProxyUrlParsed;
54
-
55
- this.isClosed = false;
56
- }
57
-
58
- _createClass(HandlerTunnelTcpChain, [{
59
- key: 'bindHandlersToThis',
60
- value: function bindHandlersToThis(handlerNames) {
61
- var _this = this;
62
-
63
- handlerNames.forEach(function (evt) {
64
- _this[evt] = _this[evt].bind(_this);
65
- });
66
- }
67
- }, {
68
- key: 'run',
69
- value: function run() {
70
- this.log('Connecting to upstream proxy...');
71
-
72
- var options = {
73
- method: 'CONNECT',
74
- hostname: this.upstreamProxyUrlParsed.hostname,
75
- port: this.upstreamProxyUrlParsed.port,
76
- path: this.trgParsed.hostname + ':' + this.trgParsed.port,
77
- headers: {}
78
- };
79
-
80
- (0, _tools.maybeAddProxyAuthorizationHeader)(this.upstreamProxyUrlParsed, options.headers);
81
-
82
- this.trgRequest = _http2.default.request(options);
83
-
84
- this.trgRequest.once('connect', this.onTrgRequestConnect);
85
- this.trgRequest.once('abort', this.onTrgRequestAbort);
86
- this.trgRequest.once('error', this.onTrgRequestError);
87
- this.trgRequest.on('socket', this.onTrgSocket);
88
-
89
- // Send the data
90
- this.trgRequest.end();
91
- }
92
-
93
- // If the client closes the connection prematurely,
94
- // then immediately destroy the upstream socket, there's nothing we can do with it
95
-
96
- }, {
97
- key: 'onSrcSocketClose',
98
- value: function onSrcSocketClose() {
99
- if (this.isClosed) return;
100
- this.log('Source socket closed');
101
- this.close();
102
- }
103
- }, {
104
- key: 'onSrcSocketEnd',
105
- value: function onSrcSocketEnd() {
106
- if (this.isClosed) return;
107
- this.log('Source socket ended');
108
- this.close();
109
- }
110
- }, {
111
- key: 'onSrcSocketError',
112
- value: function onSrcSocketError(err) {
113
- if (this.isClosed) return;
114
- this.log('Source socket failed: ' + (err.stack || err));
115
- this.close();
116
- }
117
- }, {
118
- key: 'onTrgSocket',
119
- value: function onTrgSocket(socket) {
120
- if (this.isClosed) return;
121
-
122
- this.log('Target socket assigned');
123
-
124
- this.trgSocket = socket;
125
-
126
- socket.once('close', this.onTrgSocketClose);
127
- socket.once('end', this.onTrgSocketEnd);
128
- socket.once('error', this.onTrgSocketError);
129
- }
130
-
131
- // Once target socket closes, we need to give time
132
- // to source socket to receive pending data, so we only call end()
133
-
134
- }, {
135
- key: 'onTrgSocketClose',
136
- value: function onTrgSocketClose() {
137
- var _this2 = this;
138
-
139
- if (this.isClosed) return;
140
- this.log('Target socket closed');
141
- setTimeout(function () {
142
- if (_this2.srcSocket) _this2.srcSocket.end();
143
- }, 100);
144
- }
145
- }, {
146
- key: 'onTrgSocketEnd',
147
- value: function onTrgSocketEnd() {
148
- var _this3 = this;
149
-
150
- if (this.isClosed) return;
151
- this.log('Target socket ended');
152
- setTimeout(function () {
153
- if (_this3.srcSocket) _this3.srcSocket.end();
154
- }, 100);
155
- }
156
- }, {
157
- key: 'onTrgSocketError',
158
- value: function onTrgSocketError(err) {
159
- if (this.isClosed) return;
160
- this.log('Target socket failed: ' + (err.stack || err));
161
- this.fail(err);
162
- }
163
- }, {
164
- key: 'onTrgRequestConnect',
165
- value: function onTrgRequestConnect(response) {
166
- if (this.isClosed) return;
167
- this.log('Connected to upstream proxy');
168
-
169
- if (this.checkUpstreamProxy407(response)) return;
170
-
171
- // Setup bi-directional tunnel
172
- this.trgSocket.pipe(this.srcSocket);
173
- this.srcSocket.pipe(this.trgSocket);
174
-
175
- this.srcSocket.resume();
176
- }
177
- }, {
178
- key: 'onTrgRequestAbort',
179
- value: function onTrgRequestAbort() {
180
- if (this.isClosed) return;
181
- this.log('Target aborted');
182
- this.close();
183
- }
184
- }, {
185
- key: 'onTrgRequestError',
186
- value: function onTrgRequestError(err) {
187
- if (this.isClosed) return;
188
- this.log('Target request failed: ' + (err.stack || err));
189
- this.fail(err);
190
- }
191
-
192
- /**
193
- * Checks whether response from upstream proxy is 407 Proxy Authentication Required
194
- * and if so, responds 502 Bad Gateway to client.
195
- * @param response
196
- * @return {boolean}
197
- */
198
-
199
- }, {
200
- key: 'checkUpstreamProxy407',
201
- value: function checkUpstreamProxy407(response) {
202
- if (this.upstreamProxyUrlParsed && response.statusCode === 407) {
203
- this.fail('Invalid credentials provided for the upstream proxy.', 502);
204
- return true;
205
- }
206
- return false;
207
- }
208
- }, {
209
- key: 'fail',
210
- value: function fail(err, statusCode) {
211
- if (this.srcGotResponse) {
212
- this.log('Source already received a response, just destroying the socket...');
213
- this.close();
214
- } else if (statusCode) {
215
- // Manual error
216
- this.log(err + ', responding with custom status code ' + statusCode + ' to client');
217
- } else if (err.code === 'ENOTFOUND' && !this.upstreamProxyUrlParsed) {
218
- this.log('Target server not found, sending 404 to client');
219
- } else if (err.code === 'ENOTFOUND' && this.upstreamProxyUrlParsed) {
220
- this.log('Upstream proxy not found, sending 502 to client');
221
- } else if (err.code === 'ECONNREFUSED') {
222
- this.log('Upstream proxy refused connection, sending 502 to client');
223
- } else if (err.code === 'ETIMEDOUT') {
224
- this.log('Connection timed out, sending 502 to client');
225
- } else if (err.code === 'ECONNRESET') {
226
- this.log('Connection lost, sending 502 to client');
227
- } else if (err.code === 'EPIPE') {
228
- this.log('Socket closed before write, sending 502 to client');
229
- } else {
230
- this.log('Unknown error, sending 500 to client');
231
- }
232
- }
233
- /**
234
- * Detaches all listeners and destroys all sockets.
235
- */
236
-
237
- }, {
238
- key: 'close',
239
- value: function close() {
240
- if (!this.isClosed) {
241
- this.log('Closing handler');
242
-
243
- if (this.srcRequest) {
244
- this.srcRequest.destroy();
245
- this.srcRequest = null;
246
- }
247
-
248
- if (this.srcSocket) {
249
- this.srcSocket.destroy();
250
- this.srcSocket = null;
251
- }
252
-
253
- if (this.trgRequest) {
254
- this.trgRequest.abort();
255
- this.trgRequest = null;
256
- }
257
-
258
- if (this.trgSocket) {
259
- this.trgSocket.destroy();
260
- this.trgSocket = null;
261
- }
262
-
263
- this.isClosed = true;
264
- }
265
- }
266
- }]);
267
-
268
- return HandlerTunnelTcpChain;
269
- }();
270
-
271
- exports.default = HandlerTunnelTcpChain;