获取待验证的期望值和实际值

@return {
querystring: {
"参数名": {
expectedValue: "期望值",
factValue: "实际值"
}
},
header: {},
body: {}
}
495618
function getRequestValues(request, mockRequestConfig) {
    var querystring = mockRequestConfig ? mockRequestConfig.querystring : {};
    var header = mockRequestConfig ? mockRequestConfig.header : {};
    var body = mockRequestConfig ? mockRequestConfig.body : {};

    // 先找出所有的必选参数, 最后一起做验证
    var requestValues = {
        querystring: {},
        header: {},
        body: {}
    };

    // 验证请求接口时是否包含特定的 querystring 参数
    if (querystring) {
        for (var expectedName in querystring) {
            // 只验证必传参数
            if (isRequired(expectedName)) {
                // 去除用作必要参数的标识
                var _expectedName = stripRequiredPlaceholder(expectedName);
                var expectedValue = querystring[expectedName];
                var factValue = request.query[_expectedName];

                requestValues.querystring[_expectedName] = {
                    expectedValue: expectedValue,
                    factValue: factValue
                };
            }
        }
    }

    // 验证请求接口时是否包含特定的 header
    if (header) {
        for (var expectedName in header) {
            if (isRequired(expectedName)) {
                var _expectedName = stripRequiredPlaceholder(expectedName);
                var expectedValue = header[expectedName];
                var factValue = request.get(_expectedName);

                requestValues.header[_expectedName] = {
                    expectedValue: expectedValue,
                    factValue: factValue ? decodeURIComponent(factValue) : factValue
                };
            }
        }
    }

    // 验证请求接口时是否包含特定的 body 数据
    if (body) {
        // request's "Content-Type" HTTP header field matches the MIME type
        // http://expressjs.com/en/4x/api.html#req.is
        if (request.is('application/x-www-form-urlencoded')) {
            // XXX nodejs 自带的 querystring 无法解析嵌套的对象
            // 例如: querystring 是 a%5Bb%5D%3D1, 解析出来为 {'a[b]': 1}
            // 但是我们想要的是 {a:{b:1}}
            var urlencoded = qs.parse(request._rawBody);

            for (var expectedName in body) {
                if (isRequired(expectedName)) {
                    var _expectedName = stripRequiredPlaceholder(expectedName);
                    var expectedValue = body[expectedName];
                    var factValue = urlencoded[_expectedName];

                    requestValues.body[_expectedName] = {
                        expectedValue: expectedValue,
                        factValue: factValue
                    };
                }
            }
        } else if (request.is('multipart/form-data')) {
            // multipart/form-data 一般用得比较少, 简单的使用正则表达式来解析
            var multipartRegExp = /Content-Disposition:\s*form-data;\s*name\s*=\s*"(\S+)"\s+(\S+)/mg;

            var multipartFormData = {};
            var result = null;
            while ((result = multipartRegExp.exec(request._rawBody)) != null) {
                // 从表单数据中匹配出字段名和字段值
                var fieldName = result[1];
                var fieldValue = result[2];
                multipartFormData[fieldName] = fieldValue;
            }

            for (var expectedName in body) {
                if (isRequired(expectedName)) {
                    var _expectedName = stripRequiredPlaceholder(expectedName);
                    var expectedValue = body[expectedName];
                    var factValue = multipartFormData[_expectedName];

                    requestValues.body[_expectedName] = {
                        expectedValue: expectedValue,
                        factValue: factValue
                    };
                }
            }
        } else if (request.is('json')) {
            var factValue = null;
            try {
                factValue = JSON.parse(decodeURIComponent(request._rawBody));
            } catch (e) {
                factValue = request._rawBody;
                console.warn('body json parse error', e);
            }

            // 在 body 中放置 raw 数据时, 不是 key-value 键值对形式的数据
            // 因此使用 Content-Type MIME 作为 key 来标记
            // 但是不验证里面具体的数据类型, 只验证其是否是 object 类型
            requestValues.body[request.get('Content-Type')] = {
                expectedValue: body,
                factValue: factValue
            };
        } else {
            // 针对其他的 MIME 类似数据不做验证, 都认为他们是字符串
            // 希望扩展的人可以扩展验证规则
            if (!util.isEmptyObject(body)) {
                requestValues.body[request.get('Content-Type')] = {
                    expectedValue: body.toString(),
                    _expectedValue: body,
                    factValue: request._rawBody + ' ' // 不管你有没有传 body, 都伪造了一个非空的值
                };
            }
        }
    }

    return requestValues;
}
576303
function () {
		var result = [];
		var args = arguments;
		var l = args.length;
		var name, value;
		for (var i = 0; i < l; i++) {
			name = args[i];
			value = this.getValue(name);
			result.push(value);
		}
		return result;
	}
1160755
public static function getAutoParamName()
    {
        $index = RequestContext::get('dbParamInc', 0);
        if($index >= 65535) // 限制dechex()结果最长为ffff，一般一个查询也不会用到这么多参数，足够了
        {
            $index = 0;
        }
        ++$index;
        RequestContext::set('dbParamInc', $index);
        return ':p' . dechex($index);
    }
1030589
public List<List<String>> asStructured() {
		if (values.isEmpty()) {
			return Collections.emptyList();
		}

		JsonValue first = values.get(0);

		//["request-status", {}, "text", ["2.0", "Success"] ]
		List<JsonValue> array = first.getArray();
		if (array != null) {
			List<List<String>> components = new ArrayList<List<String>>(array.size());
			for (JsonValue value : array) {
				if (value.isNull()) {
					components.add(Arrays.<String> asList());
					continue;
				}

				Object obj = value.getValue();
				if (obj != null) {
					String s = obj.toString();
					List<String> component = (s.length() == 0) ? Arrays.<String> asList() : Arrays.asList(s);
					components.add(component);
					continue;
				}

				List<JsonValue> subArray = value.getArray();
				if (subArray != null) {
					List<String> component = new ArrayList<String>(subArray.size());
					for (JsonValue subArrayValue : subArray) {
						if (subArrayValue.isNull()) {
							component.add("");
							continue;
						}

						obj = subArrayValue.getValue();
						if (obj != null) {
							component.add(obj.toString());
							continue;
						}
					}
					if (component.size() == 1 && component.get(0).length() == 0) {
						component.clear();
					}
					components.add(component);
				}
			}
			return components;
		}

		//get the first value if it's not enclosed in an array
		//["request-status", {}, "text", "2.0"]
		Object obj = first.getValue();
		if (obj != null) {
			List<List<String>> components = new ArrayList<List<String>>(1);
			String s = obj.toString();
			List<String> component = (s.length() == 0) ? Arrays.<String> asList() : Arrays.asList(s);
			components.add(component);
			return components;
		}

		//["request-status", {}, "text", null]
		if (first.isNull()) {
			List<List<String>> components = new ArrayList<List<String>>(1);
			components.add(Arrays.<String> asList());
			return components;
		}

		return Collections.emptyList();
	}
721315
function(request) {
  var options = {};

  if (request.getQueryParameters()) {
    options.query = request.getQueryParameters();
  }

  if (
    request.getHeaders() &&
    request.getHeaders()['Content-Type'] === 'application/json'
  ) {
    options.data = JSON.stringify(request.getBodyParameters());
  } else if (request.getBodyParameters()) {
    options.data = request.getBodyParameters();
  }

  if (request.getHeaders()) {
    options.headers = request.getHeaders();
  }
  return options;
}
332436
function defaultValue (req) {
  return (req.body && req.body._csrf) ||
    (req.query && req.query._csrf) ||
    (req.headers['csrf-token']) ||
    (req.headers['xsrf-token']) ||
    (req.headers['x-csrf-token']) ||
    (req.headers['x-xsrf-token'])
}
1205703
function() {
  var server = this.get("server");
  if (!server)
    return null;
  var address = server.address();
  var scheme = server instanceof https.Server ? 'https' : 'http';
  return util.format("%s://%s:%d", scheme, address.address, address.port);
}
284051
function htmlParse() {
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '<div></div>';
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  var transData = {}; //存放转化后的数据

  var res = {}; //返回的数据

  transData = (0, _html2json.html2json)(data, 'root', options); // console.log('解析结果是', transData);

  res = transData;
  return res;
}
121531
function (url) {
      var query = url.split('?')[1];
      var data = query.split("&");
      var result = {};
      for(var i=0; i<data.length; i++) {
        var item = data[i].split("=");
        result[item[0]] = item[1];
      }
      return result;
    }
861740
function() {
        var e, spo;

        if(this.falseFact) {
            spo = 'FALSE';
        } else {
            spo = '(' + Utils.removeBeforeSharp(this.subject) + ', ' + Utils.removeBeforeSharp(this.predicate) + ', ' + Utils.removeBeforeSharp(this.object) + ')'
        }

        this.explicit ? e = 'E' : e = 'I';
        return e + spo;
    }
256905
function getData() {
  var o = {}, k, v;
  for(k in this._data) {
    v = this._data[k].v;
    // must coerce to strings here
    if(typeof v === 'number') {
      v = '' + v;
    }
    o[k] = v;
  }
  return o;
}
525190
function () {
            var result = {
                name: this._name
            };
            if (!this._test) {
                result.test = false;
            }
            if (this._tags.length) {
                result.tags = this._tags.join(" ");
            }
            return result;
        }
596599
public String getBodyStr() {
        ArrayList<String> arr = new ArrayList<String>();
        if (bodyFormat.equals(EBodyFormat.FORM_KV)) {
            for (Map.Entry<String, Object> entry : body.entrySet()) {
                if (entry.getValue() == null || entry.getValue().equals("")) {
                    arr.add(Util.uriEncode(entry.getKey(), true));
                } else {
                    arr.add(String.format("%s=%s", Util.uriEncode(entry.getKey(), true),
                            Util.uriEncode(entry.getValue().toString(), true)));
                }
            }
            return Util.mkString(arr.iterator(), '&');
        }
        else if (bodyFormat.equals(EBodyFormat.RAW_JSON)) {
            JSONObject json = new JSONObject();
            for (Map.Entry<String, Object> entry : body.entrySet()) {
                json.put(entry.getKey(), entry.getValue());
            }
            return json.toString();
        }
        else if (bodyFormat.equals(EBodyFormat.RAW_JSON_ARRAY)) {
            return (String) body.get("body");
        }
        return "";
    }
683025
function () {
        return {
            /**
             * 是否不存在 placeholder 时候，根据规则自动添加 placeholder
             *
             * @type {boolean}
             */
            autoInsertPlaceholder: true,

            /**
             * 模块加载器文件名
             *
             * @type {Array.<string>}
             */
            loaderScripts: ['require.js', 'esl.js', 'mod.js', 'sea.js', 'system.js'],
	    
            /**
             * 脚本占位符
             *
             * @type {string}
             */
            scriptPlaceholder: '<!--SCRIPT_PLACEHOLDER-->',
	    
            /**
             * 异步脚本占位符
             *
             * @type {string}
             */
            scriptAsyncPlaceholder: '<!--SCRIPT_ASYNC_PLACEHOLDER-->',

            /**
             * 样式占位符
             *
             * @type {string}
             */
            stylePlaceholder: '<!--STYLE_PLACEHOLDER-->',

            /**
             * 资源配置占位符
             *
             * @type {string}
             */
            resourceConfigPlaceholder:
                fis.config.get('placeholder.requireconfig')
                || '<!--RESOURCECONFIG_PLACEHOLDER-->'
        };
    }
224516
function() {
    var i = 2
      , la = this.lookahead(i).type;

    while ('space' == la) la = this.lookahead(++i).type;

    switch (la) {
      // Assignment
      case '=':
      case '?=':
      case '-=':
      case '+=':
      case '*=':
      case '/=':
      case '%=':
        return this.assignment();
      // Member
      case '.':
        if ('space' == this.lookahead(i - 1).type) return this.selector();
        if (this._ident == this.peek()) return this.id();
        while ('=' != this.lookahead(++i).type
          && !~['[', ',', 'newline', 'indent', 'eos'].indexOf(this.lookahead(i).type)) ;
        if ('=' == this.lookahead(i).type) {
          this._ident = this.peek();
          return this.expression();
        } else if (this.looksLikeSelector() && this.stateAllowsSelector()) {
          return this.selector();
        }
      // Assignment []=
      case '[':
        if (this._ident == this.peek()) return this.id();
        while (']' != this.lookahead(i++).type
          && 'selector' != this.lookahead(i).type
          && 'eos' != this.lookahead(i).type) ;
        if ('=' == this.lookahead(i).type) {
          this._ident = this.peek();
          return this.expression();
        } else if (this.looksLikeSelector() && this.stateAllowsSelector()) {
          return this.selector();
        }
      // Operation
      case '-':
      case '+':
      case '/':
      case '*':
      case '%':
      case '**':
      case '&&':
      case '||':
      case '>':
      case '<':
      case '>=':
      case '<=':
      case '!=':
      case '==':
      case '?':
      case 'in':
      case 'is a':
      case 'is defined':
        // Prevent cyclic .ident, return literal
        if (this._ident == this.peek()) {
          return this.id();
        } else {
          this._ident = this.peek();
          switch (this.currentState()) {
            // unary op or selector in property / for
            case 'for':
            case 'selector':
              return this.property();
            // Part of a selector
            case 'root':
            case 'atblock':
            case 'atrule':
              return '[' == la
                ? this.subscript()
                : this.selector();
            case 'function':
            case 'conditional':
              return this.looksLikeSelector()
                ? this.selector()
                : this.expression();
            // Do not disrupt the ident when an operand
            default:
              return this.operand
                ? this.id()
                : this.expression();
          }
        }
      // Selector or property
      default:
        switch (this.currentState()) {
          case 'root':
            return this.selector();
          case 'for':
          case 'selector':
          case 'function':
          case 'conditional':
          case 'atblock':
          case 'atrule':
            return this.property();
          default:
            var id = this.id();
            if ('interpolation' == this.previousState()) id.mixin = true;
            return id;
        }
    }
  }
354766
function(query) {
        var queryObj = {q: ''};
        if(!query) {
            return queryObj;
        }

        var qArray = query.split('&');
        var qObj = qs.parse(query);
        for(var i = 0, len = qArray.length; i < len; i++) {
            var queryItem = decodeURIComponent(qArray[i]).replace('=', '');
            if(/^\?/g.test(queryItem)) {
                debug('matched query: %s', queryItem) ;
                queryObj.q = queryItem;
                break;
            }
        }

        queryObj.m = qObj._mcss == 'true' || qObj._mcss == 'y';
        return queryObj;
    }
607248
public String toQueryString() {
        String encoding = request.getCharacterEncoding();
        try {
            return WebUtils.toQueryString(this, encoding);
        }
        catch (UnsupportedEncodingException e) {
            throw new ControllerExecutionException("Unable to convert parameter map [" + this +
                 "] to a query string: " + e.getMessage(), e);
        }
    }