Skip to content

Commit

Permalink
refactor: refine code
Browse files Browse the repository at this point in the history
  • Loading branch information
avwo committed May 10, 2021
1 parent e15bc30 commit 0ad8e9e
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/rules/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var PATTERN_FILTER_RE = /^(?:filter|ignore):\/\/(.+)\/(i)?$/;
var LINE_PROPS_RE = /^lineProps:\/\/(.*)$/;
var FILTER_RE = /^(?:excludeFilter|includeFilter):\/\/(.*)$/;
var PROPS_FILTER_RE = /^(?:filter|excludeFilter|includeFilter|ignore):\/\/(m(?:ethod)?|i(?:p)?|h(?:eader)?|s(?:tatusCode)?|b(?:ody)?|clientIp|clientIP|serverIp|serverIP|re[qs](?:H(?:eaders?)?)?):(.+)$/;
var PURE_FILTER_RE = /^(?:excludeFilter|includeFilter):\/\/(statusCode|clientId|clientIp|clientIP|serverIp|serverIP|re[qs](?:H(?:eaders?)?)?)\.(.+)$/;
var PURE_FILTER_RE = /^(?:excludeFilter|includeFilter):\/\/(statusCode|clientIp|clientIP|serverIp|serverIP|re[qs](?:H(?:eaders?)?)?)\.(.+)$/;
var PATTERN_WILD_FILTER_RE = /^(?:filter|ignore):\/\/(!)?(\*+\/)/;
var WILD_FILTER_RE = /^(\*+\/)/;
var regUrlCache = {};
Expand All @@ -57,7 +57,7 @@ var TPL_RE = /^((?:[\w.-]+:)?\/\/)?(`.*`)$/;
// url: protocol, host, port, hostname, search, query, pathname, path, href, query.key
// req|res: ip, method, statusCode, headers?.key, cookies?.key
var PLUGIN_NAME_RE = /^[a-z\d_\-]+(?:\.replace\(.+\))?$/;
var TPL_VAR_RE = /(\$)?\$\{(\{)?(id|reqId|whistle|now|port|realPort|version|url|hostname|query|search|queryString|searchString|path|pathname|clientId|ip|clientIp|serverIp|method|status(?:Code)|reqCookies?|resCookies?|re[qs]H(?:eaders?)?)(?:\.([^{}]+))?\}(\})?/ig;
var TPL_VAR_RE = /(\$)?\$\{(\{)?(id|reqId|whistle|now|port|realPort|version|url|hostname|query|search|queryString|searchString|path|pathname|clientId|localClientId|ip|clientIp|serverIp|method|status(?:Code)|reqCookies?|resCookies?|re[qs]H(?:eaders?)?)(?:\.([^{}]+))?\}(\})?/ig;
var REPLACE_PATTERN_RE = /(^|\.)replace\((.+)\)$/i;
var SEP_RE = /^[?/]/;
var COMMA1_RE = /\\,/g;
Expand Down Expand Up @@ -477,10 +477,7 @@ function resolveMethodVar(req, key) {
function resolveStatusCodeVar(req, key) {
return req.statusCode || '';
}
function resolveReqHeadersVar(req, key) {
var value = resolvePropValue(req.headers, key);
return !value && key === 'x-whistle-client-id' ? req.clientId : value;
}

function resolveResHeadersVar(req, key) {
return resolvePropValue(req.resHeaders, key);
}
Expand Down Expand Up @@ -546,6 +543,8 @@ function resolveVarValue(req, escape, name, key) {
return resolveClientIpVar(req, key);
case 'clientid':
return req.clientId;
case 'localclientid':
return config.clientId;
case 'statuscode':
case 'status':
return resolveStatusCodeVar(req, key);
Expand All @@ -554,7 +553,7 @@ function resolveVarValue(req, escape, name, key) {
case 'reqh':
case 'reqheader':
case 'reqheaders':
return resolveReqHeadersVar(req, key);
return resolvePropValue(req.headers, key);
case 'hostname':
return util.hostname();
default:
Expand Down

0 comments on commit 0ad8e9e

Please sign in to comment.