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AS,GAmCrD,QAAQ,QAAU,CAAC,EAAK,IAAS,QAAQ,GAAK,KAAK,GAanD,QAAQ,MAAS,GAAQ,QAAQ,GAAK,QAYtC,QAAQ,SAAW,SAAU,EAAK,GAChC,MAAM,EAAgB,QAAQ,GAAK,SAAS,GAC5C,OAAQ,aAAyB,MAAS,EAAc,GAAK,CAC/D,EAYA,QAAQ,UAAa,GAAQ,QAAQ,GAAK,YAY1C,QAAQ,SAAW,SAAU,EAAK,GAChC,MAAM,EAAmB,QAAQ,GAAK,SAAS,GAC/C,OAAQ,aAA4B,MAAS,EAAiB,GAAK,CACrE,EAYA,QAAQ,UAAa,GAAQ,QAAQ,GAAK,YAa1C,QAAQ,QAAU,SAAU,EAAK,GAC/B,MAAM,EAAmB,QAAQ,GAAK,QAAQ,GAC9C,OAAQ,aAA4B,MAAS,EAAiB,GAAK,CACrE,EAaA,QAAQ,SAAY,GAAQ,QAAQ,GAAK,WAkBzC,QAAQ,QAAW,GAAQ,GAAG,QAAQ","file":"/npm/node-req@2.1.2/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/node-req@2.1.2/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict'\n\n/**\n * node-req\n * Copyright(c) 2015-2015 Harminder Virk\n * MIT Licensed\n*/\n\nconst parseurl = require('parseurl')\nconst qs = require('qs')\nconst fresh = require('fresh')\nconst proxyaddr = require('proxy-addr')\nconst isIP = require('net').isIP\nconst accepts = require('accepts')\nconst is = require('type-is')\n\nconst compileTrust = function (value) {\n  /**\n   * If value is a function, return it right away.\n   */\n  if (typeof (value) === 'function') {\n    return value\n  }\n\n  /**\n   * Wrap a boolean true inside a function\n   * and return true\n   */\n  if (value === true) {\n    return function () {\n      return true\n    }\n  }\n\n  /**\n   * Wrap number inside a function and perform\n   * required operations.\n   */\n  if (typeof (value) === 'number') {\n    return function (a, i) {\n      return i < value\n    }\n  }\n\n  /**\n   * Support comma-separated values\n   */\n  if (typeof value === 'string') {\n    value = value.split(/ *, */)\n  }\n\n  /**\n   * Finally let proxyaddr understand\n   * and compile the input.\n   */\n  return proxyaddr.compile(value || [])\n}\n\n/**\n * Facade over Node.js http.IncomingMessage request\n *\n * @module Request\n */\nlet Request = exports = module.exports = {}\n\n/**\n * Parses query string from url an returns an object.\n *\n * @method get\n *\n * @param  {http.IncomingMessage} req\n * @param  {Object}               [options]    Options are passed to https://www.npmjs.com/package/qs\n *\n * @return {Object}\n *\n * @example\n * ```js\n * const queryString = nodeReq.get(req)\n * ```\n */\nRequest.get = (req, options = {}) => qs.parse(parseurl(req).query, options)\n\n/**\n * Returns the exact copy of `request.method`. Defined\n * [here](https://nodejs.org/api/http.html#http_message_method)\n *\n * @method method\n *\n * @param  {http.IncomingMessage} req\n *\n * @return {String}\n *\n * @example\n * ```js\n * const method = nodeReq.method(req)\n * ```\n */\nRequest.method = (req) => req.method\n\n/**\n * Returns an object of headers for a given\n * request.\n *\n * @method headers\n *\n * @param  {http.IncomingMessage} req\n *\n * @return {Object}\n *\n * @example\n * ```js\n * const headers = nodeReq.headers(req)\n * ```\n */\nRequest.headers = (req) => req.headers\n\n/**\n * Returns header value for a given key. Also\n * it will handle the inconsistencies between\n * `referer` and `referrer` header.\n *\n * @method header\n *\n * @param  {http.IncomingMessage} req\n * @param  {String} key\n * @return {String}\n *\n * @example\n * ```js\n * const authHeader = nodeReq.header(req, 'Authorization')\n * ```\n */\nRequest.header = function (req, key) {\n  key = key.toLowerCase()\n  const headers = Request.headers(req)\n\n  switch (key) {\n    case 'referer':\n    case 'referrer':\n      return headers.referrer || headers.referer || ''\n    default:\n      return headers[key] || ''\n  }\n}\n\n/**\n * Returns the freshness of a response inside the client\n * cache. If client cache has the latest response, this\n * method will return `true`, otherwise it will return\n * `false`.\n *\n * Also when HTTP header `Cache-Control: no-cache` is present\n * this method will return false everytime.\n *\n * @method fresh\n *\n * @param  {http.IncomingMessage} req\n * @param  {http.ServerResponse}  res\n *\n * @return {Boolean}\n *\n * @example\n * ```js\n * if (nodeReq.fresh(req, res)) {\n *    res.writeHead(304)\n * }\n * ```\n */\nRequest.fresh = function (req, res) {\n  const method = Request.method(req)\n  const status = res.statusCode\n\n  /**\n   * only for GET and HEAD\n   */\n  if (method !== 'GET' && method !== 'HEAD') {\n    return false\n  }\n\n  /**\n   * 2xx or 304 as per rfc2616 14.26\n   */\n  if ((status >= 200 && status < 300) || status === 304) {\n    const responseHeaders = typeof (res.getHeaders) === 'function' ? res.getHeaders() : (res._headers || {})\n    return fresh(req.headers, responseHeaders)\n  }\n\n  return false\n}\n\n/**\n * This method is the opposite of the `nodeReq.fresh`\n *\n * @method stale\n *\n * @param  {http.IncomingMessage} req\n * @param  {http.ServerResponse}  res\n *\n * @return {Boolean}\n *\n * @example\n * ```js\n * if (!nodeReq.stale(req, res)) {\n *    res.writeHead(304)\n * }\n * ```\n */\nRequest.stale = (req, res) => !Request.fresh(req, res)\n\n/**\n * Returns the most trusted ip address for the HTTP\n * request. It will handle the use cases where your\n * server is behind a proxy.\n *\n * Make sure to check [proxy-addr](https://www.npmjs.com/package/proxy-addr)\n * for the available options for `trust`.\n *\n * @method ip\n *\n * @param  {http.IncomingMessage} req\n * @param  {Mixed}                [trust]\n *\n * @return {String}\n *\n * @example\n * ```js\n * nodeReq.ip(req, '127.0.0.1')\n * nodeReq.ip(req, ['::1/128', 'fe80::/10'])\n * ```\n */\nRequest.ip = (req, trust) => proxyaddr(req, compileTrust(trust))\n\n/**\n * Returns list of all remote addresses ordered with\n * most trusted on the top of the list.\n *\n * Make sure to check [proxy-addr](https://www.npmjs.com/package/proxy-addr)\n * for the available options for `trust`.\n *\n * @method ips\n *\n * @param  {http.IncomingMessage} req\n * @param  {Mixed}  [trust]\n *\n * @return {Array}\n *\n * @example\n * ```\n * nodeReq.ips(req, '127.0.0.1')\n * nodeReq.ips(req, ['::1/128', 'fe80::/10'])\n * ```\n */\nRequest.ips = function (req, trust) {\n  const addresses = proxyaddr.all(req, compileTrust(trust))\n  return addresses.slice(1).reverse()\n}\n\n/**\n * Returns request protocol based upon encrypted\n * connection or X-Forwaded-Proto header.\n *\n * Make sure to check [proxy-addr](https://www.npmjs.com/package/proxy-addr)\n * for the available options for `trust`.\n *\n * @method protocol\n *\n * @param  {http.IncomingMessage} req\n * @param  {Mixed}                [trust]\n *\n * @return {String}\n *\n * @example\n * ```\n * const protocol = nodeReq.protocol(req)\n * ```\n */\nRequest.protocol = function (req, trust) {\n  let proto = req.connection.encrypted ? 'https' : 'http'\n  trust = compileTrust(trust)\n\n  if (!trust(req.connection.remoteAddress, 0)) {\n    return proto\n  }\n\n  proto = Request.header(req, 'X-Forwarded-Proto') || proto\n  return proto.split(/\\s*,\\s*/)[0]\n}\n\n/**\n * Looks for request protocol to check for\n * https existence or returns false.\n *\n * @method secure\n *\n * @param  {http.IncomingMessage} req\n *\n * @return {Boolean}\n *\n * @example\n * ```\n * const isHttps = nodeReq.secure(req)\n * ```\n */\nRequest.secure = (req) => Request.protocol(req) === 'https'\n\n/**\n * Returns the request subdomains as an array. Also\n * it will make sure to exclude `www` from the\n * subdomains list.\n *\n * Make sure to check [proxy-addr](https://www.npmjs.com/package/proxy-addr)\n * for the available options for `trust`.\n *\n * @method subdomains\n *\n * @param  {http.IncomingMessage} req\n * @param  {Mixed}                [trust]\n * @param  {Number}               [offset = 2] subdomain offset\n *\n * @return {Array}\n *\n * @example\n * ```js\n * const subdomains = nodeReq.subdomains(req)\n * ```\n */\nRequest.subdomains = function (req, trust, offset = 2) {\n  const hostname = Request.hostname(req, trust)\n\n  if (!hostname || isIP(hostname)) {\n    return []\n  }\n\n  const subdomains = hostname.split('.').reverse().slice(offset)\n\n  /**\n   * remove www if is the last subdomain\n   * after reverse\n   */\n  if (subdomains[subdomains.length - 1] === 'www') {\n    subdomains.splice(subdomains.length - 1, 1)\n  }\n\n  return subdomains\n}\n\n/**\n * Determines whether request is an ajax request\n * or not, based on X-Requested-With header.\n *\n * @method ajax\n *\n * @param  {http.IncomingMessage} req\n *\n * @return {Boolean}\n *\n * @example\n * ```js\n * if (nodeReq.ajax(req)) {\n *    res.writeHead(200, {\"Content-type\": \"application/json\"})\n * } else {\n *    res.writeHead(200, {\"Content-type\": \"text/html\"})\n * }\n * ```\n */\nRequest.ajax = (req) => {\n  return (Request.header(req, 'X-Requested-With') || '').toLowerCase() === 'xmlhttprequest'\n}\n\n/**\n * Tells whether request has X-Pjax\n * header or not.\n *\n * @method pjax\n *\n * @param  {http.IncomingMessage} req\n *\n * @return {Boolean}\n *\n * @example\n * ```js\n * if (nodeReq.pjax(req)) {\n *    // return partial content\n * } else {\n *    // full page refresh\n * }\n * ```\n */\nRequest.pjax = (request) => !!Request.header(request, 'X-Pjax')\n\n/**\n * Returns the hostname of HTTP request.\n *\n * Make sure to check [proxy-addr](https://www.npmjs.com/package/proxy-addr)\n * for the available options for `trust`.\n *\n * @method hostname\n *\n * @param  {http.IncomingMessage} req\n * @param  {Mixed}                [trust]\n *\n * @return {String}\n *\n * @example\n * ```js\n * const hostname = nodeReq.hostname(request)\n * ```\n */\nRequest.hostname = function (request, trust) {\n  trust = compileTrust(trust)\n  let host = Request.header(request, 'X-Forwarded-Host')\n\n  /**\n   * grabbing host header if trust proxy is disabled or host\n   * does not exists on forwared headers\n   */\n  if (!host || !trust(request.connection.remoteAddress, 0)) {\n    host = Request.header(request, 'Host')\n  }\n\n  if (!host) {\n    return null\n  }\n\n  /**\n   * Support for IPv6\n   */\n  const offset = host[0] === '[' ? host.indexOf(']') + 1 : 0\n  const index = host.indexOf(':', offset)\n  return index !== -1 ? host.substring(0, index) : host\n}\n\n/**\n * Returns request url after removing the query\n * string.\n *\n * @method url\n *\n * @param  {http.IncomingMessage} req\n *\n * @return {String}\n *\n * @example\n * ```js\n * const url = nodeReq.url(request)\n * ```\n */\nRequest.url = (req) => parseurl(req).pathname\n\n/**\n * Returns the untouched url.\n *\n * @method originalUrl\n *\n * @param  {http.IncomingMessage} req\n *\n * @return {String}\n *\n * @example\n * ```js\n * const url = nodeReq.originalUrl(request)\n * ```\n */\nRequest.originalUrl = (req) => parseurl(req).href\n\n/**\n * Tells whether request accept content of a given\n * type or not (based on **Content-type**) header.\n *\n * @method is\n *\n * @param  {http.IncomingMessage} req\n * @param  {Mixed}                keys\n *\n * @return {String}\n *\n * @example\n * ```js\n * // req.headers.content-type = 'application/json'\n *\n * nodeReq.is(req, ['json']) // json\n * nodeReq.is(req, ['json', 'html']) // json\n * nodeReq.is(req, ['application/*']) // application/json\n *\n * nodeReq.is(req, ['html']) // '<empty string>'\n * ```\n */\nRequest.is = (request, keys) => is(request, keys) || ''\n\n/**\n * Return the best possible response accepted by the\n * client. This is based on the `Accept` header.\n * [Learn more about it](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept)\n *\n * @method accepts\n *\n * @param  {http.IncomingMessage} req\n * @param  {Mixed}                keys\n *\n * @return {String}\n *\n * @example\n * ```js\n * const type = nodeReq.accepts(req, ['json', 'html'])\n *\n * switch(type) {\n *  case 'json':\n *    res.setHeader('Content-Type', 'application/json')\n *    res.write('{\"hello\":\"world!\"}')\n *    break\n *\n *  case 'html':\n *    res.setHeader('Content-Type', 'text/html')\n *    res.write('<b>hello, world!</b>')\n *    break\n *\n *  default:\n *    res.setHeader('Content-Type', 'text/plain')\n *    res.write('hello, world!')\n * }\n * ```\n */\nRequest.accepts = (req, keys) => accepts(req).type(keys)\n\n/**\n * This method is similar to {{#crossLink \"Request/accepts\"}}{{/crossLink}},\n * instead it will return an array of types from most to least preferred\n * one.\n *\n * @method types\n *\n * @param  {http.IncomingMessage} req\n *\n * @return {Array}\n */\nRequest.types = (req) => accepts(req).types()\n\n/**\n * Returns one of the most preferrable language.\n *\n * @method language\n *\n * @param  {http.IncomingMessage} req\n * @param  {Array} accepted\n *\n * @return {String}\n */\nRequest.language = function (req, accepted) {\n  const acceptedLangs = accepts(req).language(accepted)\n  return (acceptedLangs instanceof Array) ? acceptedLangs[0] : acceptedLangs\n}\n\n/**\n * Returns list of all accepted languages from most\n * to least preferred one.\n *\n * @method languages\n *\n * @param  {http.IncomingMessage} req\n *\n * @return {Array}\n */\nRequest.languages = (req) => accepts(req).languages()\n\n/**\n * Returns the best maching encoding\n *\n * @method encoding\n *\n * @param  {http.IncomingMessage} req\n * @param  {Array} accepted\n *\n * @return {String}\n */\nRequest.encoding = function (req, accepted) {\n  const acceptedEncoding = accepts(req).encoding(accepted)\n  return (acceptedEncoding instanceof Array) ? acceptedEncoding[0] : acceptedEncoding\n}\n\n/**\n * Returns list of all encodings from most\n * to least preferred one.\n *\n * @method encodings\n *\n * @param  {http.IncomingMessage} req\n *\n * @return {Array}\n */\nRequest.encodings = (req) => accepts(req).encodings()\n\n/**\n * Returns the best maching charset based upon\n * `Accept-Charset` header.\n *\n * @method charset\n *\n * @param  {http.IncomingMessage} req\n * @param  {Array}                accepted\n *\n * @return {String}\n */\nRequest.charset = function (req, accepted) {\n  const acceptedCharsets = accepts(req).charset(accepted)\n  return (acceptedCharsets instanceof Array) ? acceptedCharsets[0] : acceptedCharsets\n}\n\n/**\n * Returns a list of all charsets from most\n * to least preferred one based upon\n * `Accept-Charset` header.\n *\n * @method charsets\n *\n * @param  {http.IncomingMessage} req\n *\n * @return {Array}\n */\nRequest.charsets = (req) => accepts(req).charsets()\n\n/**\n * Tells whether request has body or\n * not to be read by any body parser.\n *\n * @method hasBody\n *\n * @param  {http.IncomingMessage} req\n * @return {Boolean}\n *\n * @example\n * ```js\n * if (nodeReq.hasBody(request)) {\n *    // use body parser\n * }\n * ```\n */\nRequest.hasBody = (req) => is.hasBody(req)\n"]}