Files
portfolio/node_modules/.cache/babel-loader/acf7e4c458f699e00931147234a8376b.json
2021-09-20 16:54:47 -04:00

1 line
29 KiB
JSON

{"ast":null,"code":"var capability = require('./capability');\n\nvar inherits = require('inherits');\n\nvar response = require('./response');\n\nvar stream = require('readable-stream');\n\nvar toArrayBuffer = require('to-arraybuffer');\n\nvar IncomingMessage = response.IncomingMessage;\nvar rStates = response.readyStates;\n\nfunction decideMode(preferBinary, useFetch) {\n if (capability.fetch && useFetch) {\n return 'fetch';\n } else if (capability.mozchunkedarraybuffer) {\n return 'moz-chunked-arraybuffer';\n } else if (capability.msstream) {\n return 'ms-stream';\n } else if (capability.arraybuffer && preferBinary) {\n return 'arraybuffer';\n } else if (capability.vbArray && preferBinary) {\n return 'text:vbarray';\n } else {\n return 'text';\n }\n}\n\nvar ClientRequest = module.exports = function (opts) {\n var self = this;\n stream.Writable.call(self);\n self._opts = opts;\n self._body = [];\n self._headers = {};\n if (opts.auth) self.setHeader('Authorization', 'Basic ' + new Buffer(opts.auth).toString('base64'));\n Object.keys(opts.headers).forEach(function (name) {\n self.setHeader(name, opts.headers[name]);\n });\n var preferBinary;\n var useFetch = true;\n\n if (opts.mode === 'disable-fetch' || 'requestTimeout' in opts && !capability.abortController) {\n // If the use of XHR should be preferred. Not typically needed.\n useFetch = false;\n preferBinary = true;\n } else if (opts.mode === 'prefer-streaming') {\n // If streaming is a high priority but binary compatibility and\n // the accuracy of the 'content-type' header aren't\n preferBinary = false;\n } else if (opts.mode === 'allow-wrong-content-type') {\n // If streaming is more important than preserving the 'content-type' header\n preferBinary = !capability.overrideMimeType;\n } else if (!opts.mode || opts.mode === 'default' || opts.mode === 'prefer-fast') {\n // Use binary if text streaming may corrupt data or the content-type header, or for speed\n preferBinary = true;\n } else {\n throw new Error('Invalid value for opts.mode');\n }\n\n self._mode = decideMode(preferBinary, useFetch);\n self._fetchTimer = null;\n self.on('finish', function () {\n self._onFinish();\n });\n};\n\ninherits(ClientRequest, stream.Writable);\n\nClientRequest.prototype.setHeader = function (name, value) {\n var self = this;\n var lowerName = name.toLowerCase(); // This check is not necessary, but it prevents warnings from browsers about setting unsafe\n // headers. To be honest I'm not entirely sure hiding these warnings is a good thing, but\n // http-browserify did it, so I will too.\n\n if (unsafeHeaders.indexOf(lowerName) !== -1) return;\n self._headers[lowerName] = {\n name: name,\n value: value\n };\n};\n\nClientRequest.prototype.getHeader = function (name) {\n var header = this._headers[name.toLowerCase()];\n\n if (header) return header.value;\n return null;\n};\n\nClientRequest.prototype.removeHeader = function (name) {\n var self = this;\n delete self._headers[name.toLowerCase()];\n};\n\nClientRequest.prototype._onFinish = function () {\n var self = this;\n if (self._destroyed) return;\n var opts = self._opts;\n var headersObj = self._headers;\n var body = null;\n\n if (opts.method !== 'GET' && opts.method !== 'HEAD') {\n if (capability.arraybuffer) {\n body = toArrayBuffer(Buffer.concat(self._body));\n } else if (capability.blobConstructor) {\n body = new global.Blob(self._body.map(function (buffer) {\n return toArrayBuffer(buffer);\n }), {\n type: (headersObj['content-type'] || {}).value || ''\n });\n } else {\n // get utf8 string\n body = Buffer.concat(self._body).toString();\n }\n } // create flattened list of headers\n\n\n var headersList = [];\n Object.keys(headersObj).forEach(function (keyName) {\n var name = headersObj[keyName].name;\n var value = headersObj[keyName].value;\n\n if (Array.isArray(value)) {\n value.forEach(function (v) {\n headersList.push([name, v]);\n });\n } else {\n headersList.push([name, value]);\n }\n });\n\n if (self._mode === 'fetch') {\n var signal = null;\n var fetchTimer = null;\n\n if (capability.abortController) {\n var controller = new AbortController();\n signal = controller.signal;\n self._fetchAbortController = controller;\n\n if ('requestTimeout' in opts && opts.requestTimeout !== 0) {\n self._fetchTimer = global.setTimeout(function () {\n self.emit('requestTimeout');\n if (self._fetchAbortController) self._fetchAbortController.abort();\n }, opts.requestTimeout);\n }\n }\n\n global.fetch(self._opts.url, {\n method: self._opts.method,\n headers: headersList,\n body: body || undefined,\n mode: 'cors',\n credentials: opts.withCredentials ? 'include' : 'same-origin',\n signal: signal\n }).then(function (response) {\n self._fetchResponse = response;\n\n self._connect();\n }, function (reason) {\n global.clearTimeout(self._fetchTimer);\n if (!self._destroyed) self.emit('error', reason);\n });\n } else {\n var xhr = self._xhr = new global.XMLHttpRequest();\n\n try {\n xhr.open(self._opts.method, self._opts.url, true);\n } catch (err) {\n process.nextTick(function () {\n self.emit('error', err);\n });\n return;\n } // Can't set responseType on really old browsers\n\n\n if ('responseType' in xhr) xhr.responseType = self._mode.split(':')[0];\n if ('withCredentials' in xhr) xhr.withCredentials = !!opts.withCredentials;\n if (self._mode === 'text' && 'overrideMimeType' in xhr) xhr.overrideMimeType('text/plain; charset=x-user-defined');\n\n if ('requestTimeout' in opts) {\n xhr.timeout = opts.requestTimeout;\n\n xhr.ontimeout = function () {\n self.emit('requestTimeout');\n };\n }\n\n headersList.forEach(function (header) {\n xhr.setRequestHeader(header[0], header[1]);\n });\n self._response = null;\n\n xhr.onreadystatechange = function () {\n switch (xhr.readyState) {\n case rStates.LOADING:\n case rStates.DONE:\n self._onXHRProgress();\n\n break;\n }\n }; // Necessary for streaming in Firefox, since xhr.response is ONLY defined\n // in onprogress, not in onreadystatechange with xhr.readyState = 3\n\n\n if (self._mode === 'moz-chunked-arraybuffer') {\n xhr.onprogress = function () {\n self._onXHRProgress();\n };\n }\n\n xhr.onerror = function () {\n if (self._destroyed) return;\n self.emit('error', new Error('XHR error'));\n };\n\n try {\n xhr.send(body);\n } catch (err) {\n process.nextTick(function () {\n self.emit('error', err);\n });\n return;\n }\n }\n};\n/**\n * Checks if xhr.status is readable and non-zero, indicating no error.\n * Even though the spec says it should be available in readyState 3,\n * accessing it throws an exception in IE8\n */\n\n\nfunction statusValid(xhr) {\n try {\n var status = xhr.status;\n return status !== null && status !== 0;\n } catch (e) {\n return false;\n }\n}\n\nClientRequest.prototype._onXHRProgress = function () {\n var self = this;\n if (!statusValid(self._xhr) || self._destroyed) return;\n if (!self._response) self._connect();\n\n self._response._onXHRProgress();\n};\n\nClientRequest.prototype._connect = function () {\n var self = this;\n if (self._destroyed) return;\n self._response = new IncomingMessage(self._xhr, self._fetchResponse, self._mode, self._fetchTimer);\n\n self._response.on('error', function (err) {\n self.emit('error', err);\n });\n\n self.emit('response', self._response);\n};\n\nClientRequest.prototype._write = function (chunk, encoding, cb) {\n var self = this;\n\n self._body.push(chunk);\n\n cb();\n};\n\nClientRequest.prototype.abort = ClientRequest.prototype.destroy = function () {\n var self = this;\n self._destroyed = true;\n global.clearTimeout(self._fetchTimer);\n if (self._response) self._response._destroyed = true;\n if (self._xhr) self._xhr.abort();else if (self._fetchAbortController) self._fetchAbortController.abort();\n};\n\nClientRequest.prototype.end = function (data, encoding, cb) {\n var self = this;\n\n if (typeof data === 'function') {\n cb = data;\n data = undefined;\n }\n\n stream.Writable.prototype.end.call(self, data, encoding, cb);\n};\n\nClientRequest.prototype.flushHeaders = function () {};\n\nClientRequest.prototype.setTimeout = function () {};\n\nClientRequest.prototype.setNoDelay = function () {};\n\nClientRequest.prototype.setSocketKeepAlive = function () {}; // Taken from http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader%28%29-method\n\n\nvar unsafeHeaders = ['accept-charset', 'accept-encoding', 'access-control-request-headers', 'access-control-request-method', 'connection', 'content-length', 'cookie', 'cookie2', 'date', 'dnt', 'expect', 'host', 'keep-alive', 'origin', 'referer', 'te', 'trailer', 'transfer-encoding', 'upgrade', 'via'];","map":{"version":3,"sources":["/Users/tylerkoenig/Code/personal/react-scss2/node_modules/stream-http/lib/request.js"],"names":["capability","require","inherits","response","stream","toArrayBuffer","IncomingMessage","rStates","readyStates","decideMode","preferBinary","useFetch","fetch","mozchunkedarraybuffer","msstream","arraybuffer","vbArray","ClientRequest","module","exports","opts","self","Writable","call","_opts","_body","_headers","auth","setHeader","Buffer","toString","Object","keys","headers","forEach","name","mode","abortController","overrideMimeType","Error","_mode","_fetchTimer","on","_onFinish","prototype","value","lowerName","toLowerCase","unsafeHeaders","indexOf","getHeader","header","removeHeader","_destroyed","headersObj","body","method","concat","blobConstructor","global","Blob","map","buffer","type","headersList","keyName","Array","isArray","v","push","signal","fetchTimer","controller","AbortController","_fetchAbortController","requestTimeout","setTimeout","emit","abort","url","undefined","credentials","withCredentials","then","_fetchResponse","_connect","reason","clearTimeout","xhr","_xhr","XMLHttpRequest","open","err","process","nextTick","responseType","split","timeout","ontimeout","setRequestHeader","_response","onreadystatechange","readyState","LOADING","DONE","_onXHRProgress","onprogress","onerror","send","statusValid","status","e","_write","chunk","encoding","cb","destroy","end","data","flushHeaders","setNoDelay","setSocketKeepAlive"],"mappings":"AAAA,IAAIA,UAAU,GAAGC,OAAO,CAAC,cAAD,CAAxB;;AACA,IAAIC,QAAQ,GAAGD,OAAO,CAAC,UAAD,CAAtB;;AACA,IAAIE,QAAQ,GAAGF,OAAO,CAAC,YAAD,CAAtB;;AACA,IAAIG,MAAM,GAAGH,OAAO,CAAC,iBAAD,CAApB;;AACA,IAAII,aAAa,GAAGJ,OAAO,CAAC,gBAAD,CAA3B;;AAEA,IAAIK,eAAe,GAAGH,QAAQ,CAACG,eAA/B;AACA,IAAIC,OAAO,GAAGJ,QAAQ,CAACK,WAAvB;;AAEA,SAASC,UAAT,CAAqBC,YAArB,EAAmCC,QAAnC,EAA6C;AAC5C,MAAIX,UAAU,CAACY,KAAX,IAAoBD,QAAxB,EAAkC;AACjC,WAAO,OAAP;AACA,GAFD,MAEO,IAAIX,UAAU,CAACa,qBAAf,EAAsC;AAC5C,WAAO,yBAAP;AACA,GAFM,MAEA,IAAIb,UAAU,CAACc,QAAf,EAAyB;AAC/B,WAAO,WAAP;AACA,GAFM,MAEA,IAAId,UAAU,CAACe,WAAX,IAA0BL,YAA9B,EAA4C;AAClD,WAAO,aAAP;AACA,GAFM,MAEA,IAAIV,UAAU,CAACgB,OAAX,IAAsBN,YAA1B,EAAwC;AAC9C,WAAO,cAAP;AACA,GAFM,MAEA;AACN,WAAO,MAAP;AACA;AACD;;AAED,IAAIO,aAAa,GAAGC,MAAM,CAACC,OAAP,GA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UAAxB,GAAqC,YAAY,CAAE,CAAnD;;AACA3D,aAAa,CAAC2B,SAAd,CAAwB4E,UAAxB,GAAqC,YAAY,CAAE,CAAnD;;AACAvG,aAAa,CAAC2B,SAAd,CAAwB6E,kBAAxB,GAA6C,YAAY,CAAE,CAA3D,C,CAEA;;;AACA,IAAIzE,aAAa,GAAG,CACnB,gBADmB,EAEnB,iBAFmB,EAGnB,gCAHmB,EAInB,+BAJmB,EAKnB,YALmB,EAMnB,gBANmB,EAOnB,QAPmB,EAQnB,SARmB,EASnB,MATmB,EAUnB,KAVmB,EAWnB,QAXmB,EAYnB,MAZmB,EAanB,YAbmB,EAcnB,QAdmB,EAenB,SAfmB,EAgBnB,IAhBmB,EAiBnB,SAjBmB,EAkBnB,mBAlBmB,EAmBnB,SAnBmB,EAoBnB,KApBmB,CAApB","sourcesContent":["var capability = require('./capability')\nvar inherits = require('inherits')\nvar response = require('./response')\nvar stream = require('readable-stream')\nvar toArrayBuffer = require('to-arraybuffer')\n\nvar IncomingMessage = response.IncomingMessage\nvar rStates = response.readyStates\n\nfunction decideMode (preferBinary, useFetch) {\n\tif (capability.fetch && useFetch) {\n\t\treturn 'fetch'\n\t} else if (capability.mozchunkedarraybuffer) {\n\t\treturn 'moz-chunked-arraybuffer'\n\t} else if (capability.msstream) {\n\t\treturn 'ms-stream'\n\t} else if (capability.arraybuffer && preferBinary) {\n\t\treturn 'arraybuffer'\n\t} else if (capability.vbArray && preferBinary) {\n\t\treturn 'text:vbarray'\n\t} else {\n\t\treturn 'text'\n\t}\n}\n\nvar ClientRequest = module.exports = function (opts) {\n\tvar self = this\n\tstream.Writable.call(self)\n\n\tself._opts = opts\n\tself._body = []\n\tself._headers = {}\n\tif (opts.auth)\n\t\tself.setHeader('Authorization', 'Basic ' + new Buffer(opts.auth).toString('base64'))\n\tObject.keys(opts.headers).forEach(function (name) {\n\t\tself.setHeader(name, opts.headers[name])\n\t})\n\n\tvar preferBinary\n\tvar useFetch = true\n\tif (opts.mode === 'disable-fetch' || ('requestTimeout' in opts && !capability.abortController)) {\n\t\t// If the use of XHR should be preferred. Not typically needed.\n\t\tuseFetch = false\n\t\tpreferBinary = true\n\t} else if (opts.mode === 'prefer-streaming') {\n\t\t// If streaming is a high priority but binary compatibility and\n\t\t// the accuracy of the 'content-type' header aren't\n\t\tpreferBinary = false\n\t} else if (opts.mode === 'allow-wrong-content-type') {\n\t\t// If streaming is more important than preserving the 'content-type' header\n\t\tpreferBinary = !capability.overrideMimeType\n\t} else if (!opts.mode || opts.mode === 'default' || opts.mode === 'prefer-fast') {\n\t\t// Use binary if text streaming may corrupt data or the content-type header, or for speed\n\t\tpreferBinary = true\n\t} else {\n\t\tthrow new Error('Invalid value for opts.mode')\n\t}\n\tself._mode = decideMode(preferBinary, useFetch)\n\tself._fetchTimer = null\n\n\tself.on('finish', function () {\n\t\tself._onFinish()\n\t})\n}\n\ninherits(ClientRequest, stream.Writable)\n\nClientRequest.prototype.setHeader = function (name, value) {\n\tvar self = this\n\tvar lowerName = name.toLowerCase()\n\t// This check is not necessary, but it prevents warnings from browsers about setting unsafe\n\t// headers. To be honest I'm not entirely sure hiding these warnings is a good thing, but\n\t// http-browserify did it, so I will too.\n\tif (unsafeHeaders.indexOf(lowerName) !== -1)\n\t\treturn\n\n\tself._headers[lowerName] = {\n\t\tname: name,\n\t\tvalue: value\n\t}\n}\n\nClientRequest.prototype.getHeader = function (name) {\n\tvar header = this._headers[name.toLowerCase()]\n\tif (header)\n\t\treturn header.value\n\treturn null\n}\n\nClientRequest.prototype.removeHeader = function (name) {\n\tvar self = this\n\tdelete self._headers[name.toLowerCase()]\n}\n\nClientRequest.prototype._onFinish = function () {\n\tvar self = this\n\n\tif (self._destroyed)\n\t\treturn\n\tvar opts = self._opts\n\n\tvar headersObj = self._headers\n\tvar body = null\n\tif (opts.method !== 'GET' && opts.method !== 'HEAD') {\n\t\tif (capability.arraybuffer) {\n\t\t\tbody = toArrayBuffer(Buffer.concat(self._body))\n\t\t} else if (capability.blobConstructor) {\n\t\t\tbody = new global.Blob(self._body.map(function (buffer) {\n\t\t\t\treturn toArrayBuffer(buffer)\n\t\t\t}), {\n\t\t\t\ttype: (headersObj['content-type'] || {}).value || ''\n\t\t\t})\n\t\t} else {\n\t\t\t// get utf8 string\n\t\t\tbody = Buffer.concat(self._body).toString()\n\t\t}\n\t}\n\n\t// create flattened list of headers\n\tvar headersList = []\n\tObject.keys(headersObj).forEach(function (keyName) {\n\t\tvar name = headersObj[keyName].name\n\t\tvar value = headersObj[keyName].value\n\t\tif (Array.isArray(value)) {\n\t\t\tvalue.forEach(function (v) {\n\t\t\t\theadersList.push([name, v])\n\t\t\t})\n\t\t} else {\n\t\t\theadersList.push([name, value])\n\t\t}\n\t})\n\n\tif (self._mode === 'fetch') {\n\t\tvar signal = null\n\t\tvar fetchTimer = null\n\t\tif (capability.abortController) {\n\t\t\tvar controller = new AbortController()\n\t\t\tsignal = controller.signal\n\t\t\tself._fetchAbortController = controller\n\n\t\t\tif ('requestTimeout' in opts && opts.requestTimeout !== 0) {\n\t\t\t\tself._fetchTimer = global.setTimeout(function () {\n\t\t\t\t\tself.emit('requestTimeout')\n\t\t\t\t\tif (self._fetchAbortController)\n\t\t\t\t\t\tself._fetchAbortController.abort()\n\t\t\t\t}, opts.requestTimeout)\n\t\t\t}\n\t\t}\n\n\t\tglobal.fetch(self._opts.url, {\n\t\t\tmethod: self._opts.method,\n\t\t\theaders: headersList,\n\t\t\tbody: body || undefined,\n\t\t\tmode: 'cors',\n\t\t\tcredentials: opts.withCredentials ? 'include' : 'same-origin',\n\t\t\tsignal: signal\n\t\t}).then(function (response) {\n\t\t\tself._fetchResponse = response\n\t\t\tself._connect()\n\t\t}, function (reason) {\n\t\t\tglobal.clearTimeout(self._fetchTimer)\n\t\t\tif (!self._destroyed)\n\t\t\t\tself.emit('error', reason)\n\t\t})\n\t} else {\n\t\tvar xhr = self._xhr = new global.XMLHttpRequest()\n\t\ttry {\n\t\t\txhr.open(self._opts.method, self._opts.url, true)\n\t\t} catch (err) {\n\t\t\tprocess.nextTick(function () {\n\t\t\t\tself.emit('error', err)\n\t\t\t})\n\t\t\treturn\n\t\t}\n\n\t\t// Can't set responseType on really old browsers\n\t\tif ('responseType' in xhr)\n\t\t\txhr.responseType = self._mode.split(':')[0]\n\n\t\tif ('withCredentials' in xhr)\n\t\t\txhr.withCredentials = !!opts.withCredentials\n\n\t\tif (self._mode === 'text' && 'overrideMimeType' in xhr)\n\t\t\txhr.overrideMimeType('text/plain; charset=x-user-defined')\n\n\t\tif ('requestTimeout' in opts) {\n\t\t\txhr.timeout = opts.requestTimeout\n\t\t\txhr.ontimeout = function () {\n\t\t\t\tself.emit('requestTimeout')\n\t\t\t}\n\t\t}\n\n\t\theadersList.forEach(function (header) {\n\t\t\txhr.setRequestHeader(header[0], header[1])\n\t\t})\n\n\t\tself._response = null\n\t\txhr.onreadystatechange = function () {\n\t\t\tswitch (xhr.readyState) {\n\t\t\t\tcase rStates.LOADING:\n\t\t\t\tcase rStates.DONE:\n\t\t\t\t\tself._onXHRProgress()\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\t// Necessary for streaming in Firefox, since xhr.response is ONLY defined\n\t\t// in onprogress, not in onreadystatechange with xhr.readyState = 3\n\t\tif (self._mode === 'moz-chunked-arraybuffer') {\n\t\t\txhr.onprogress = function () {\n\t\t\t\tself._onXHRProgress()\n\t\t\t}\n\t\t}\n\n\t\txhr.onerror = function () {\n\t\t\tif (self._destroyed)\n\t\t\t\treturn\n\t\t\tself.emit('error', new Error('XHR error'))\n\t\t}\n\n\t\ttry {\n\t\t\txhr.send(body)\n\t\t} catch (err) {\n\t\t\tprocess.nextTick(function () {\n\t\t\t\tself.emit('error', err)\n\t\t\t})\n\t\t\treturn\n\t\t}\n\t}\n}\n\n/**\n * Checks if xhr.status is readable and non-zero, indicating no error.\n * Even though the spec says it should be available in readyState 3,\n * accessing it throws an exception in IE8\n */\nfunction statusValid (xhr) {\n\ttry {\n\t\tvar status = xhr.status\n\t\treturn (status !== null && status !== 0)\n\t} catch (e) {\n\t\treturn false\n\t}\n}\n\nClientRequest.prototype._onXHRProgress = function () {\n\tvar self = this\n\n\tif (!statusValid(self._xhr) || self._destroyed)\n\t\treturn\n\n\tif (!self._response)\n\t\tself._connect()\n\n\tself._response._onXHRProgress()\n}\n\nClientRequest.prototype._connect = function () {\n\tvar self = this\n\n\tif (self._destroyed)\n\t\treturn\n\n\tself._response = new IncomingMessage(self._xhr, self._fetchResponse, self._mode, self._fetchTimer)\n\tself._response.on('error', function(err) {\n\t\tself.emit('error', err)\n\t})\n\n\tself.emit('response', self._response)\n}\n\nClientRequest.prototype._write = function (chunk, encoding, cb) {\n\tvar self = this\n\n\tself._body.push(chunk)\n\tcb()\n}\n\nClientRequest.prototype.abort = ClientRequest.prototype.destroy = function () {\n\tvar self = this\n\tself._destroyed = true\n\tglobal.clearTimeout(self._fetchTimer)\n\tif (self._response)\n\t\tself._response._destroyed = true\n\tif (self._xhr)\n\t\tself._xhr.abort()\n\telse if (self._fetchAbortController)\n\t\tself._fetchAbortController.abort()\n}\n\nClientRequest.prototype.end = function (data, encoding, cb) {\n\tvar self = this\n\tif (typeof data === 'function') {\n\t\tcb = data\n\t\tdata = undefined\n\t}\n\n\tstream.Writable.prototype.end.call(self, data, encoding, cb)\n}\n\nClientRequest.prototype.flushHeaders = function () {}\nClientRequest.prototype.setTimeout = function () {}\nClientRequest.prototype.setNoDelay = function () {}\nClientRequest.prototype.setSocketKeepAlive = function () {}\n\n// Taken from http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader%28%29-method\nvar unsafeHeaders = [\n\t'accept-charset',\n\t'accept-encoding',\n\t'access-control-request-headers',\n\t'access-control-request-method',\n\t'connection',\n\t'content-length',\n\t'cookie',\n\t'cookie2',\n\t'date',\n\t'dnt',\n\t'expect',\n\t'host',\n\t'keep-alive',\n\t'origin',\n\t'referer',\n\t'te',\n\t'trailer',\n\t'transfer-encoding',\n\t'upgrade',\n\t'via'\n]\n"]},"metadata":{},"sourceType":"script"}