Default value function, checking the `req.body`
and `req.query` for the CSRF token.

@param {IncomingMessage} req
@return {String}
@api private
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'])
}
1210425
function parseListRequest(req){
  var reqObj = {};
  reqObj.originalUrl = req.originalUrl;
  reqObj.uid = req.params.guid;
  reqObj.env = req.params.environment;
  reqObj.domain = req.params.domain;
  return reqObj;
}
969587
function clientReq(req) {
    if (!req) {
        return (req);
    }

    var host;

    try {
        host = req.host.split(':')[0];
    } catch (e) {
        host = false;
    }

    return ({
        method: req ? req.method : false,
        url: req ? req.path : false,
        address: host,
        port: req ? req.port : false,
        headers: req ? req.headers : false
    });
}
1070825
function getCharset (req) {
  try {
    return contentType.parse(req).parameters.charset.toLowerCase()
  } catch (e) {
    return undefined
  }
}
341095
function getResponseMessage( err, req, env ) {
  var content_type = req.get( 'content-type' ) || ''
  var message = err.toString()

  if ( content_type.indexOf( 'application/json' ) !== -1 ) {
    message = {
      error: {
        code: err.code || null,
        errorCode: err.errorCode || null,
        message: err.toString(),
        status: err.status || null,
        statusCode: err.statusCode || 500
      }
    }
  } else if ( env === 'development' ) {
    message = '<pre>' + err.stack
  }

  return message
}
1124770
function reqres(res, req) {
    if (req && req._headers) {
        throw new Error('Received response object where request object was expected');
    }
    this.res = res;
    this.req = req;
    if (res) {
        if (res.$ && res.$.data) {
            this.data = res.$.data;
        }
        else {
            this.data = { error: null };
            if (!res.$) {
                res.$ = this;
            }
        }
    }
}
239537
def _default_body(self):
        
        if not self.data:
            return ""
        if self.content_type == 'application/json':
            import json
            return json.dumps(self.data)
        elif self.content_type == 'application/x-www-form-urlencoded':
            import urllib
            return urllib.urlencode(self.data)
        else:
            raise NotImplementedError(
                "You must manually encode the request "
                "body for '{}'".format(self.content_type)
            )
395275
function parseDeleteRequest(req){
  var reqObj = {};
  reqObj.originalUrl = req.originalUrl;
  reqObj.uid = req.params.guid;
  reqObj.env =req.params.environment;
  reqObj.domain = req.params.domain;
  reqObj._id = req.params.id;
  return reqObj;
}
1353068
function getValueBuffer(key, req, stringify) {
  var val = this.getKey(key, req);
  // should have buffer, string or number
  if(val !== undefined) {
    if(typeof val === 'number' && !stringify) val = new Buffer([val]);
    val = (val instanceof Buffer) ? val : new Buffer('' + val);
  }
  return val;
}
848395
function getCSRFToken() {
		if (typeof document === "undefined") return null;
		var cookies = document.cookie.split(";");//$NON-NLS-0$

		var i,n,v;
		for(i = 0; i<cookies.length; i++) {
			n = cookies[i].substr(0, cookies[i].indexOf("=")).trim();//$NON-NLS-0$
			v = cookies[i].substr(cookies[i].indexOf("=") + 1).trim();//$NON-NLS-0$

			if(n.endsWith(XSRF_TOKEN)) {
				return v;
			}
		}
	}
100590
function AuthChallengeMessage(token) {
  var _token = token || new Buffer(0);

  Response.call(this, 0x0E);

  Object.defineProperty(this, 'token', {
    set: function(val) { _token = val; },
    get: function() { return _token; }
  });
}
742290
function getBody(req) {
  return new Promise((resolve, reject) => {
    let data = '';
    req
      .on('data', (chunk) => {
        data += chunk;
      })
      .on('end', () => {
        resolve(data);
      })
      .on('error', reject);
  });
}
995645
function(req) {
    var fields = {};

    // Fields
    if (_.isString(req.query.fields)) {
      _.forEach(req.query.fields.split(','), function(field) {
        fields[field] = 1;
      });
    }

    return fields;
  }
164938
def request_token(params)
    if scope = Util.arglist(params.delete(:scope))
      params[:scope] = Util.strlist(scope)
    end
    headers = {'content-type' => FORM_UTF8, 'accept' => JSON_UTF8,
        'authorization' => Http.basic_auth(@client_id, @client_secret) }
    reply = json_parse_reply(@key_style, *request(@token_target, :post,
        '/oauth/token', Util.encode_form(params), headers))
    raise BadResponse unless reply[jkey :token_type] && reply[jkey :access_token]
    TokenInfo.new(reply)
  end
1087793
function default_onRequest(request) {
    if (-1 == request.requestedProtocols.indexOf(exports.wsProtocol)) {
      return request.reject()
    }

    request.accept(exports.wsProtocol, request.origin)
  }
1230914
function normalizeRequestParameters (defaultsObject, paramsName, requestParams) {
  var promise = new Promise(function (resolve, reject) {
    var defaultParams;
    var onlyOne;
  
    // First check if we have a default parameters object with this name
    if (typeof defaultsObject[paramsName] !== 'object') reject(new RequiredError(`No default parameters for '${paramsName}'`, paramsName, defaultsObject[paramsName]));
    
    // Create an empty object with default parameters
    defaultParams = extend(Object.create(null), defaultsObject[paramsName]);
    
    // Check if there is only one required parameter in defaults
    onlyOne = checkIfOnlyOneRequired(defaultParams);
    
    // If checked parameters are not an object
    if (typeof requestParams !== 'object') {
      // If they are a string or a valid number and there is only one required parameter in default parameters
      if ((typeof requestParams === 'string' || (typeof requestParams === 'number' && isNaN(requestParams))) && onlyOne !== false) {
        // Provide this value as a value in the default params
        defaultParams[onlyOne] = requestParams;
      } else {
        // Reject with error in other case
        reject(new RequiredError('No request parameters provided', 'requestParams', requestParams));
      }
    }
    
    for (var key in defaultParams) {
      if (checkRequiredParameter(requestParams[key]) && defaultParams[key] === '') {
        reject(new RequiredError(`Missing required parameter '${key}'`, key, requestParams[key]));
      } else if (!checkRequiredParameter(requestParams[key])) {
        defaultParams[key] = requestParams[key];
      }
      if (defaultParams[key] === '__optional') defaultParams[key] = '';
    }
    
    resolve(defaultParams);
    
  });
  
  return promise;
}
915060
private function injectJqueryToResponse(string $body, string $tokenValue): string
    {
        $regex = '/(.*?)(<\/body>)/is';
        $jQueryCode = sprintf(
            '<script>$.ajaxSetup({beforeSend: function (xhr) { xhr.setRequestHeader("X-CSRF-Token","%s"); }});</script>',
            $tokenValue
        );
        $body = preg_replace($regex, '$1' . $jQueryCode . '$2', $body, -1, $count) ?? '';

        if (!$count) {
            // Inject JS code anyway
            $body .= $jQueryCode;
        }

        return $body;
    }