whistle 2.9.11 → 2.9.12

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.
@@ -409,6 +409,9 @@ function resolveWebsocket(socket, wss) {
409
409
  if (isProxyPort) {
410
410
  proxyHeaders[config.WEBUI_HEAD] = 1;
411
411
  }
412
+ if (util.isLocalPHost(socket, wss)) {
413
+ headers[config.WEBUI_HEAD] = 1;
414
+ }
412
415
  var clientId = headers[config.CLIENT_ID_HEADER];
413
416
  if (clientId) {
414
417
  proxyHeaders[config.CLIENT_ID_HEADER] = clientId;
@@ -350,7 +350,8 @@ module.exports = function (req, res, next) {
350
350
  }
351
351
  if (isProxyPort) {
352
352
  proxyHeaders[config.WEBUI_HEAD] = 1;
353
- } else if (util.isProxyPort(curServerPort)) {
353
+ }
354
+ if (util.isProxyPort(curServerPort) || util.isLocalPHost(req, isHttps)) {
354
355
  headers[config.WEBUI_HEAD] = 1;
355
356
  }
356
357
  var clientId = req.headers[config.CLIENT_ID_HEADER];
@@ -431,7 +432,8 @@ module.exports = function (req, res, next) {
431
432
  } else {
432
433
  if (
433
434
  isProxyPort ||
434
- util.isProxyPort(options.port || (isHttps ? 443 : 80))
435
+ util.isProxyPort(options.port || (isHttps ? 443 : 80)) ||
436
+ util.isLocalPHost(req, isHttps)
435
437
  ) {
436
438
  headers[config.WEBUI_HEAD] = 1;
437
439
  }
@@ -124,19 +124,20 @@ exports.getProxy = function (url, req, callback) {
124
124
  var ignoreProxy;
125
125
  var proxy;
126
126
  var pacRule;
127
- var phost;
127
+ var host = rules.getHost(req, pRules, fRules, hRules);
128
+ var hostValue = util.getMatcherValue(host) || '';
128
129
  if (config.multiEnv || req._headerRulesFirst) {
129
130
  proxy =
130
- (pRules && pRules.resolveProxy(req)) ||
131
- (hRules && hRules.resolveProxy(req)) ||
132
- rules.resolveProxy(req) ||
133
- (fRules && fRules.resolveProxy(req));
131
+ (pRules && pRules.resolveProxy(req, hostValue)) ||
132
+ (hRules && hRules.resolveProxy(req, hostValue)) ||
133
+ rules.resolveProxy(req, hostValue) ||
134
+ (fRules && fRules.resolveProxy(req, hostValue));
134
135
  } else {
135
136
  proxy =
136
- (pRules && pRules.resolveProxy(req)) ||
137
- rules.resolveProxy(req) ||
138
- (fRules && fRules.resolveProxy(req)) ||
139
- (hRules && hRules.resolveProxy(req));
137
+ (pRules && pRules.resolveProxy(req, hostValue)) ||
138
+ rules.resolveProxy(req, hostValue) ||
139
+ (fRules && fRules.resolveProxy(req, hostValue)) ||
140
+ (hRules && hRules.resolveProxy(req, hostValue));
140
141
  }
141
142
  var proxyHostOnly = isLineProp(proxy, 'proxyHostOnly');
142
143
  var proxyHost =
@@ -154,7 +155,7 @@ exports.getProxy = function (url, req, callback) {
154
155
  proxyHost = proxyHost || PROXY_HOSTS_RE.test(proxy.matcher);
155
156
  }
156
157
  }
157
- var host = rules.getHost(req, pRules, fRules, hRules);
158
+
158
159
  if (!ignoreProxy) {
159
160
  proxyHost = isProxyHost(req, proxy, host) || proxyHost; // 不能调换顺序
160
161
  }
@@ -207,10 +208,7 @@ exports.getProxy = function (url, req, callback) {
207
208
  resolvePacRule();
208
209
  }
209
210
  if (proxyHost) {
210
- phost = parseUrl(util.setProtocol(host.matcher + (host.port ? ':' + host.port : '')));
211
- if (util.checkProxyHost(proxy, phost)) {
212
- req._phost = phost;
213
- }
211
+ req._phost = parseUrl(util.setProtocol(host.matcher + (host.port ? ':' + host.port : '')));
214
212
  } else if (
215
213
  !isLineProp(proxy, 'proxyFirst') &&
216
214
  !isLineProp(host, 'proxyFirst') &&
@@ -229,10 +227,7 @@ exports.getProxy = function (url, req, callback) {
229
227
  }
230
228
  if (proxy) {
231
229
  if (!req._phost && P_HOST_RE.test(proxy.matcher)) {
232
- phost = parseUrl(util.setProtocol(RegExp.$1));
233
- if (util.checkProxyHost(proxy, phost)) {
234
- req._phost = phost;
235
- }
230
+ req._phost = parseUrl(util.setProtocol(RegExp.$1));
236
231
  }
237
232
  reqRules.proxy = proxy;
238
233
  return callback();
@@ -268,7 +263,7 @@ exports.getProxy = function (url, req, callback) {
268
263
  if (rule) {
269
264
  tempRules.parse(pacRule.rawPattern + ' ' + rule);
270
265
  req.curUrl = url;
271
- if ((proxy = tempRules.resolveProxy(req))) {
266
+ if ((proxy = tempRules.resolveProxy(req, hostValue))) {
272
267
  proxyHost = isProxyHost(req, proxy) || proxyHost; // 不能调换顺序
273
268
  req._proxyTunnel =
274
269
  req._proxyTunnel || isLineProp(pacRule, 'proxyTunnel');
@@ -724,8 +724,8 @@ function getValueFor(key, vals) {
724
724
  return values.get(key);
725
725
  }
726
726
 
727
- function getRule(req, list, vals, index, isFilter) {
728
- var rule = resolveRuleList(req, list, vals, index || 0, isFilter);
727
+ function getRule(req, list, vals, index, isFilter, host) {
728
+ var rule = resolveRuleList(req, list, vals, index || 0, isFilter, null, host);
729
729
  resolveValue(rule, vals, req);
730
730
  return rule;
731
731
  }
@@ -803,7 +803,7 @@ function replaceSubMatcher(url, regExp) {
803
803
  return util.replacePattern(url, regExp);
804
804
  }
805
805
 
806
- function resolveRuleList(req, list, vals, index, isFilter, isEnableProxy) {
806
+ function resolveRuleList(req, list, vals, index, isFilter, isEnableProxy, host) {
807
807
  var curUrl = formatUrl(req.curUrl);
808
808
  var notHttp = list.isRuleProto && curUrl[0] !== 'h';
809
809
  //支持域名匹配
@@ -860,7 +860,7 @@ function resolveRuleList(req, list, vals, index, isFilter, isEnableProxy) {
860
860
  if (notHttp && protoMgr.isFileProxy(rule.matcher)) {
861
861
  return false;
862
862
  }
863
- return isFilter || !matchExcludeFilters(curUrl, rule, req);
863
+ return (isFilter || !matchExcludeFilters(curUrl, rule, req)) && (host == null || util.checkProxyHost(rule, host));
864
864
  };
865
865
 
866
866
  for (var i = 0; (rule = list[i]); i++) {
@@ -1954,9 +1954,6 @@ proto.resolveHost = function (
1954
1954
  proto.lookupHost = function (req, callback) {
1955
1955
  req.curUrl = formatUrl(util.setProtocol(req.curUrl));
1956
1956
  var options = url.parse(req.curUrl);
1957
- if (options.hostname === '::1') {
1958
- return callback(null, '127.0.0.1');
1959
- }
1960
1957
  lookup(
1961
1958
  options.hostname,
1962
1959
  callback,
@@ -2226,8 +2223,8 @@ proto.hasReqScript = function (req) {
2226
2223
  : getRule(req, this._rules.rulesFile, this._values);
2227
2224
  };
2228
2225
 
2229
- proto.resolveProxy = function resolveProxy(req) {
2230
- var proxy = getRule(req, this._rules.proxy, this._values);
2226
+ proto.resolveProxy = function resolveProxy(req, host) {
2227
+ var proxy = getRule(req, this._rules.proxy, this._values, null, null, host);
2231
2228
  var matcher = proxy && proxy.matcher;
2232
2229
  var name = matcher && matcher.substring(0, matcher.indexOf(':'));
2233
2230
  var filter = this.resolveFilter(req);
package/lib/tunnel.js CHANGED
@@ -408,7 +408,7 @@ function tunnelProxy(server, proxy, type) {
408
408
  isSocks ? 1080 : isHttpsProxy ? 443 : 80
409
409
  );
410
410
  options.auth = options.auth || req._pacAuth;
411
- var isProxyPort = options.port == config.port;
411
+ var isProxyPort = util.isProxyPort(options.port);
412
412
  if (isProxyPort && util.isLocalAddress(ip)) {
413
413
  return emitError(
414
414
  new Error(
@@ -455,7 +455,7 @@ function tunnelProxy(server, proxy, type) {
455
455
  } else {
456
456
  dstOptions.proxyPort = options.port || 80;
457
457
  dstOptions.proxyAuth = options.auth;
458
- if (isProxyPort) {
458
+ if (isProxyPort || util.isLocalPHost(req, true)) {
459
459
  _headers[config.WEBUI_HEAD] = 1;
460
460
  }
461
461
  _headers['x-whistle-request-tunnel-ack'] = 1;
package/lib/util/index.js CHANGED
@@ -1824,7 +1824,7 @@ function isJSONContent(req) {
1824
1824
 
1825
1825
  exports.isJSONContent = isJSONContent;
1826
1826
 
1827
- exports.isProxyPort = function (proxyPort) {
1827
+ function isProxyPort(proxyPort) {
1828
1828
  return (
1829
1829
  proxyPort == config.port ||
1830
1830
  proxyPort == config.httpsPort ||
@@ -1832,6 +1832,17 @@ exports.isProxyPort = function (proxyPort) {
1832
1832
  proxyPort == config.socksPort ||
1833
1833
  proxyPort == config.realPort
1834
1834
  );
1835
+ }
1836
+
1837
+ exports.isProxyPort = isProxyPort;
1838
+
1839
+ exports.isLocalPHost = function(req, isHttps) {
1840
+ var phost = req._phost;
1841
+ var hostname = phost && phost.hostname;
1842
+ if (!hostname || !isProxyPort(phost.port || (isHttps ? 443 : 80))) {
1843
+ return false;
1844
+ }
1845
+ return isLocalHost(hostname);
1835
1846
  };
1836
1847
 
1837
1848
  function isMultipart(req) {
@@ -3650,9 +3661,8 @@ function checkProxyHost(host, filter) {
3650
3661
  return filter.not ? !result : result;
3651
3662
  }
3652
3663
 
3653
- exports.checkProxyHost = function(proxy, phost) {
3664
+ exports.checkProxyHost = function(proxy, host) {
3654
3665
  var filters = proxy && proxy.hostFilter;
3655
- var host = phost.host;
3656
3666
  if (filters) {
3657
3667
  if (!host) {
3658
3668
  return false;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "whistle",
3
3
  "description": "HTTP, HTTP2, HTTPS, Websocket debugging proxy",
4
- "version": "2.9.11",
4
+ "version": "2.9.12",
5
5
  "dataDirname": ".whistle",
6
6
  "localUIHost": "local.whistlejs.com",
7
7
  "port": 8899,