UNPKG

webtorrent

Version:

Streaming torrent client

1 lines 1.05 MB
var t={8748(t,e,r){var i=r(717);const n=r(8957),s=r(537),o=r(7007),a=s.debuglog("http");function h(t){if(!(this instanceof h))return new h(t);o.call(this);var e=this;e.defaultPort=80,e.protocol="http:",e.options=s._extend({},t),e.options.path=null,e.requests={},e.sockets={},e.freeSockets={},e.keepAliveMsecs=e.options.keepAliveMsecs||1e3,e.keepAlive=e.options.keepAlive||!1,e.maxSockets=e.options.maxSockets||h.defaultMaxSockets,e.maxFreeSockets=e.options.maxFreeSockets||256,e.on("free",function(t,r){var i=e.getName(r);if(a("agent.on(free)",i),t.writable&&e.requests[i]&&e.requests[i].length)e.requests[i].shift().onSocket(t),0===e.requests[i].length&&delete e.requests[i];else{var n=t._httpMessage;if(n&&n.shouldKeepAlive&&t.writable&&e.keepAlive){var s=e.freeSockets[i],o=s?s.length:0,h=o;e.sockets[i]&&(h+=e.sockets[i].length),h>e.maxSockets||o>=e.maxFreeSockets?t.destroy():(s=s||[],e.freeSockets[i]=s,t.setKeepAlive(!0,e.keepAliveMsecs),t.unref(),t._httpMessage=null,e.removeSocket(t,r),s.push(t))}else t.destroy()}})}s.inherits(h,o),e.Agent=h,h.defaultMaxSockets=1/0,h.prototype.createConnection=n.createConnection,h.prototype.getName=function(t){var e=t.host||"localhost";return e+=":",t.port&&(e+=t.port),e+=":",t.localAddress&&(e+=t.localAddress),4!==t.family&&6!==t.family||(e+=":"+t.family),e},h.prototype.addRequest=function(t,e){"string"==typeof e&&(e={host:e,port:arguments[2],localAddress:arguments[3]}),e=s._extend({},e),e=s._extend(e,this.options);var r=this.getName(e);this.sockets[r]||(this.sockets[r]=[]);var n=this.freeSockets[r]?this.freeSockets[r].length:0,o=n+this.sockets[r].length;if(n){var h=this.freeSockets[r].shift();a("have free socket"),this.freeSockets[r].length||delete this.freeSockets[r],h.ref(),t.onSocket(h),this.sockets[r].push(h)}else o<this.maxSockets?(a("call onSocket",o,n),this.createSocket(t,e,function(e,r){e?i.nextTick(function(){t.emit("error",e)}):t.onSocket(r)})):(a("wait for socket"),this.requests[r]||(this.requests[r]=[]),this.requests[r].push(t))},h.prototype.createSocket=function(t,e,r){var i=this;if(e=s._extend({},e),!(e=s._extend(e,i.options)).servername){e.servername=e.host;const r=t.getHeader("host");r&&(e.servername=r.replace(/:.*$/,""))}var n=i.getName(e);e._agentKey=n,a("createConnection",n,e),e.encoding=null;var o=!1;const h=i.createConnection(e,u);function u(t,s){if(!o){if(o=!0,t)return r(t);i.sockets[n]||(i.sockets[n]=[]),i.sockets[n].push(s),a("sockets",n,i.sockets[n].length),s.on("free",h),s.on("close",u),s.on("agentRemove",function t(){a("CLIENT socket onRemove"),i.removeSocket(s,e),s.removeListener("close",u),s.removeListener("free",h),s.removeListener("agentRemove",t)}),r(null,s)}function h(){i.emit("free",s,e)}function u(t){a("CLIENT socket onClose"),i.removeSocket(s,e)}}h&&u(null,h)},h.prototype.removeSocket=function(t,e){var r=this.getName(e);a("removeSocket",r,"writable:",t.writable);var n=[this.sockets];t.writable||n.push(this.freeSockets);for(var s=0;s<n.length;s++){var o=n[s];if(o[r]){var h=o[r].indexOf(t);-1!==h&&(o[r].splice(h,1),0===o[r].length&&delete o[r])}}if(this.requests[r]&&this.requests[r].length){a("removeSocket, have a request, make a socket");var u=this.requests[r][0];this.createSocket(u,e,function(t,e){t?i.nextTick(function(){u.emit("error",t)}):e.emit("free")})}},h.prototype.destroy=function(){for(var t=[this.freeSockets,this.sockets],e=0;e<t.length;e++)for(var r=t[e],i=Object.keys(r),n=0;n<i.length;n++)for(var s=r[i[n]],o=0;o<s.length;o++)s[o].destroy()},e.globalAgent=new h},5930(t,e,r){var i=r(717);const n=r(537),s=r(8957),o=r(8835),a=r(5905).HTTPParser,h=r(4529).ok,u=r(2728),f=u.httpSocketSetup,l=u.parsers,c=u.freeParser,d=u.debug,p=r(8419).OutgoingMessage,m=r(8748),g=r(8287).Buffer;function y(t,e){var r=this;if(p.call(r),"string"==typeof t){if(!(t=o.parse(t)).hostname)throw new Error("Unable to determine the domain name")}else t=n._extend({},t);var a=t.agent,h=t._defaultAgent||m.globalAgent;!1===a?a=new h.constructor:null==a&&"function"!=typeof t.createConnection&&(a=h),r.agent=a;var f=t.protocol||h.protocol,l=h.protocol;if(r.agent&&r.agent.protocol&&(l=r.agent.protocol),t.path&&/ /.test(t.path))throw new TypeError("Request path contains unescaped characters");if(f!==l)throw new Error('Protocol "'+f+'" not supported. Expected "'+l+'"');const c=t.defaultPort||r.agent&&r.agent.defaultPort;var y=t.port=t.port||c||80,b=t.host=t.hostname||t.host||"localhost";if(void 0===t.setHost)var v=!0;r.socketPath=t.socketPath;var w=r.method=(t.method||"GET").toUpperCase();if(!u._checkIsHttpToken(w))throw new TypeError("Method must be a valid HTTP token");if(r.path=t.path||"/",e&&r.once("response",e),!Array.isArray(t.headers)){if(t.headers)for(var _=Object.keys(t.headers),M=0,S=_.length;M<S;M++){var k=_[M];r.setHeader(k,t.headers[k])}if(b&&!this.getHeader("host")&&v){var E=b,x=-1;-1!==(x=E.indexOf(":"))&&-1!==(x=E.indexOf(":",x))&&"["!==E[0]&&(E=`[${E}]`),y&&+y!==c&&(E+=":"+y),this.setHeader("Host",E)}}t.auth&&!this.getHeader("Authorization")&&this.setHeader("Authorization","Basic "+g.from(t.auth).toString("base64")),r.useChunkedEncodingByDefault="GET"!==w&&"HEAD"!==w&&"DELETE"!==w&&"OPTIONS"!==w&&"CONNECT"!==w,Array.isArray(t.headers)?r._storeHeader(r.method+" "+r.path+" HTTP/1.1\r\n",t.headers):r.getHeader("expect")&&r._storeHeader(r.method+" "+r.path+" HTTP/1.1\r\n",r._renderHeaders());var A=!1;if(r.socketPath){r._last=!0,r.shouldKeepAlive=!1;const t={path:r.socketPath},e=r.agent.createConnection(t,I);if(!e||A)return;A=!0,r.onSocket(e)}else if(r.agent)r.agent.keepAlive||Number.isFinite(r.agent.maxSockets)?(r._last=!1,r.shouldKeepAlive=!0):(r._last=!0,r.shouldKeepAlive=!1),r.agent.addRequest(r,t);else if(r._last=!0,r.shouldKeepAlive=!1,"function"==typeof t.createConnection){const e=t.createConnection(t,I);if(!e||A)return;A=!0,r.onSocket(e)}else d("CLIENT use net.createConnection",t),r.onSocket(s.createConnection(t));function I(t,e){A||(A=!0,t?i.nextTick(function(){r.emit("error",t)}):(r.onSocket(e),r._deferToConnect(null,null,function(){r._flush(),r=null})))}r._deferToConnect(null,null,function(){r._flush(),r=null}),this._ended=!1}function b(t){t.emit("abort")}function v(){var t=new Error("socket hang up");return t.code="ECONNRESET",t}function w(){var t=this,e=t._httpMessage;d("HTTP socket close"),t.read();var r=t.parser;if(e.emit("close"),e.res&&e.res.readable){e.res.emit("aborted");var i=e.res;i.on("end",function(){i.emit("close")}),i.push(null)}else e.res||e.socket._hadError||(e.emit("error",v()),e.socket._hadError=!0);e.output&&(e.output.length=0),e.outputEncodings&&(e.outputEncodings.length=0),r&&(r.finish(),c(r,e,t))}function _(t){var e=this,r=e._httpMessage;d("SOCKET ERROR:",t.message,t.stack),r&&(r.emit("error",t),r.socket._hadError=!0),e.read();var i=e.parser;i&&(i.finish(),c(i,r,e)),e.removeListener("data",k),e.removeListener("end",S),e.destroy()}function M(t){d("SOCKET ERROR on FREE socket:",t.message,t.stack),this.destroy(),this.emit("agentRemove")}function S(){var t=this._httpMessage,e=this.parser;t.res||t.socket._hadError||(t.emit("error",v()),t.socket._hadError=!0),e&&(e.finish(),c(e,t,this)),this.destroy()}function k(t){var e=this,r=this._httpMessage,i=this.parser;h(i&&i.socket===e);var n=i.execute(t);if(n instanceof Error)d("parse error"),c(i,r,e),e.destroy(),r.emit("error",n),r.socket._hadError=!0;else if(i.incoming&&i.incoming.upgrade){var s=n,o=i.incoming;r.res=o,e.removeListener("data",k),e.removeListener("end",S),i.finish();var a=t.slice(s,t.length),u="CONNECT"===r.method?"connect":"upgrade";r.listenerCount(u)>0?(r.upgradeOrConnect=!0,e.emit("agentRemove"),e.removeListener("close",w),e.removeListener("error",_),e._readableState.flowing=null,r.emit(u,o,e,a),r.emit("close")):e.destroy(),c(i,r,e)}else i.incoming&&i.incoming.complete&&100!==i.incoming.statusCode&&(e.removeListener("data",k),e.removeListener("end",S),c(i,r,e))}function E(t,e){var r=this.socket,i=r._httpMessage;if(i.domain&&!t.domain&&(d('setting "res.domain"'),t.domain=i.domain),d("AGENT incoming response!"),!i.res){if(i.res=t,"CONNECT"===i.method)return t.upgrade=!0,2;var n="HEAD"===i.method;return d("AGENT isHeadResponse",n),100===t.statusCode?(delete i.res,i.emit("continue"),!0):(!i.shouldKeepAlive||e||i.upgradeOrConnect||(i.shouldKeepAlive=!1),i.res=t,t.req=i,t.on("end",A),i.on("prefinish",I),i.emit("response",t)||t._dump(),n)}r.destroy()}function x(t,e){var r=e.socket;e.shouldKeepAlive?(d("AGENT socket keep-alive"),e.timeoutCb&&(r.setTimeout(0,e.timeoutCb),e.timeoutCb=null),r.removeListener("close",w),r.removeListener("error",_),r.once("error",M),i.nextTick(T,r)):(r.writable&&(d("AGENT socket.destroySoon()"),r.destroySoon()),h(!r.writable))}function A(){const t=this.req;t._ended=!0,t.shouldKeepAlive&&!t.finished||x(0,t)}function I(){const t=this;this.res;t.shouldKeepAlive&&t._ended&&x(0,t)}function T(t){t.emit("free")}function C(t,e){t.aborted?e.emit("free"):function(t,e){var r=l.alloc();t.socket=e,t.connection=e,r.reinitialize(a.RESPONSE),r.socket=e,r.incoming=null,r.outgoing=t,t.parser=r,e.parser=r,e._httpMessage=t,f(e),"number"==typeof t.maxHeadersCount?r.maxHeaderPairs=t.maxHeadersCount<<1:r.maxHeaderPairs=2e3,r.onIncoming=E,e.removeListener("error",M),e.on("error",_),e.on("data",k),e.on("end",S),e.on("close",w),t.emit("socket",e)}(t,e)}n.inherits(y,p),e.ClientRequest=y,y.prototype.aborted=void 0,y.prototype._finish=function(){p.prototype._finish.call(this)},y.prototype._implicitHeader=function(){this._storeHeader(this.method+" "+this.path+" HTTP/1.1\r\n",this._renderHeaders())},y.prototype.abort=function(){void 0===this.aborted&&i.nextTick(b,this),this.aborted=Date.now(),this.res?this.res._dump():this.once("response",function(t){t._dump()}),this.socket&&this.socket.destroy()},y.prototype.onSocket=function(t){i.nextTick(C,this,t)},y.prototype._deferToConnect=function(t,e,r){var i=this;function n(){t&&i.socket[t].apply(i.socket,e),"function"==typeof r&&r()}var s=function(){i.socket.writable?n():i.socket.once("connect",n)};i.socket?s():i.once("socket",s)},y.prototype.setTimeout=function(t,e){e&&this.once("timeout",e);var r=this;function i(){r.emit("timeout")}if(this.socket&&this.socket.writable)return this.timeoutCb&&this.socket.setTimeout(0,this.timeoutCb),this.timeoutCb=i,this.socket.setTimeout(t,i),this;if(this.timeoutCb=i,this.socket){var n=this.socket;return this.socket.once("connect",function(){n.setTimeout(t,i)}),this}return this.once("socket",function(e){e.setTimeout(t,i)}),this},y.prototype.setNoDelay=function(){const t=arguments.length,e=new Array(t);for(var r=0;r<t;r++)e[r]=arguments[r];this._deferToConnect("setNoDelay",e)},y.prototype.setSocketKeepAlive=function(){const t=arguments.length,e=new Array(t);for(var r=0;r<t;r++)e[r]=arguments[r];this._deferToConnect("setKeepAlive",e)},y.prototype.clearTimeout=function(t){this.setTimeout(0,t)}},2728(t,e,r){const i=r(5905),n=i.methods,s=i.HTTPParser,o=r(975).FreeList,a=r(3989),h=a.IncomingMessage,u=a.readStart,f=a.readStop,l=r(537).debuglog("http");e.debug=l,e.CRLF="\r\n",e.chunkExpression=/chunk/i,e.continueExpression=/100-continue/i,e.methods=n;const c=0|s.kOnHeaders,d=0|s.kOnHeadersComplete,p=0|s.kOnBody,m=0|s.kOnMessageComplete,g=0|s.kOnExecute;function y(t,e){(this.maxHeaderPairs<=0||this._headers.length<this.maxHeaderPairs)&&(this._headers=this._headers.concat(t)),this._url+=e}function b(t,e,r,i,s,o,a,u,f){var l=this;r||(r=l._headers,l._headers=[]),s||(s=l._url,l._url=""),l.incoming=new h(l.socket),l.incoming.httpVersionMajor=t,l.incoming.httpVersionMinor=e,l.incoming.httpVersion=t+"."+e,l.incoming.url=s;var c=r.length;l.maxHeaderPairs>0&&(c=Math.min(c,l.maxHeaderPairs)),l.incoming._addHeaderLines(r,c),"number"==typeof i?l.incoming.method=n[i]:(l.incoming.statusCode=o,l.incoming.statusMessage=a),!u||null===l.outgoing||void 0!==l.outgoing._headers.upgrade&&/(^|\W)upgrade(\W|$)/i.test(l.outgoing._headers.connection)||(u=!1),l.incoming.upgrade=u;var d=0;return u||(d=l.onIncoming(l.incoming,f)),"number"!=typeof d?d?1:0:d}function v(t,e,r){var i=this.incoming;if(i){var n=i.socket;if(r>0&&!i._dumped){var s=t.slice(e,e+r);i.push(s)||f(n)}}}function w(){var t=this,e=t.incoming;if(e){e.complete=!0;var r=t._headers;r&&(t.incoming._addHeaderLines(r,r.length),t._headers=[],t._url=""),e.push(null)}u(t.socket)}var _=new o("parsers",1e3,function(){var t=new s(s.REQUEST);return t._headers=[],t._url="",t._consumed=!1,t.socket=null,t.incoming=null,t.outgoing=null,t[c]=y,t[d]=b,t[p]=v,t[m]=w,t[g]=null,t});function M(){this._httpMessage&&this._httpMessage.emit("drain")}function S(t){return t>=94&&t<=122||(t>=65&&t<=90||(45===t||(t>=48&&t<=57||34!==t&&40!==t&&41!==t&&44!==t&&(t>=33&&t<=46||(124===t||126===t)))))}e.parsers=_,e.freeParser=function(t,e,r){t&&(t._headers=[],t.onIncoming=null,t._consumed&&t.unconsume(),t._consumed=!1,t.socket&&(t.socket.parser=null),t.socket=null,t.incoming=null,t.outgoing=null,t[g]=null,!1===_.free(t)&&t.close(),t=null),e&&(e.parser=null),r&&(r.parser=null)},e.httpSocketSetup=function(t){t.removeListener("drain",M),t.on("drain",M)},e._checkIsHttpToken=function(t){if("string"!=typeof t||0===t.length)return!1;if(!S(t.charCodeAt(0)))return!1;const e=t.length;if(e>1){if(!S(t.charCodeAt(1)))return!1;if(e>2){if(!S(t.charCodeAt(2)))return!1;if(e>3){if(!S(t.charCodeAt(3)))return!1;for(var r=4;r<e;r++)if(!S(t.charCodeAt(r)))return!1}}}return!0},e._checkInvalidHeaderChar=function(t){if((t+="").length<1)return!1;var e=t.charCodeAt(0);if(e<=31&&9!==e||e>255||127===e)return!0;if(t.length<2)return!1;if((e=t.charCodeAt(1))<=31&&9!==e||e>255||127===e)return!0;if(t.length<3)return!1;if((e=t.charCodeAt(2))<=31&&9!==e||e>255||127===e)return!0;for(var r=3;r<t.length;++r)if((e=t.charCodeAt(r))<=31&&9!==e||e>255||127===e)return!0;return!1}},3989(t,e,r){const i=r(537),n=r(8310);function s(t){t&&!t._paused&&t.readable&&t.resume()}function o(t){n.Readable.call(this),this._readableState.readingMore=!0,this.socket=t,this.connection=t,this.httpVersionMajor=null,this.httpVersionMinor=null,this.httpVersion=null,this.complete=!1,this.headers={},this.rawHeaders=[],this.trailers={},this.rawTrailers=[],this.readable=!0,this.upgrade=null,this.url="",this.method=null,this.statusCode=null,this.statusMessage=null,this.client=t,this._consuming=!1,this._dumped=!1}e.readStart=s,e.readStop=function(t){t&&t.pause()},i.inherits(o,n.Readable),e.IncomingMessage=o,o.prototype.setTimeout=function(t,e){return e&&this.on("timeout",e),this.socket.setTimeout(t),this},o.prototype.read=function(t){return this._consuming||(this._readableState.readingMore=!1),this._consuming=!0,this.read=n.Readable.prototype.read,this.read(t)},o.prototype._read=function(t){this.socket.readable&&s(this.socket)},o.prototype.destroy=function(t){this.socket&&this.socket.destroy(t)},o.prototype._addHeaderLines=function(t,e){if(t&&t.length){var r,i;this.complete?(r=this.rawTrailers,i=this.trailers):(r=this.rawHeaders,i=this.headers);for(var n=0;n<e;n+=2){var s=t[n],o=t[n+1];r.push(s),r.push(o),this._addHeaderLine(s,o,i)}}},o.prototype._addHeaderLine=function(t,e,r){switch(t=t.toLowerCase()){case"set-cookie":void 0!==r[t]?r[t].push(e):r[t]=[e];break;case"content-type":case"content-length":case"user-agent":case"referer":case"host":case"authorization":case"proxy-authorization":case"if-modified-since":case"if-unmodified-since":case"from":case"location":case"max-forwards":case"retry-after":case"etag":case"last-modified":case"server":case"age":case"expires":void 0===r[t]&&(r[t]=e);break;default:"string"==typeof r[t]?r[t]+=", "+e:r[t]=e}},o.prototype._dump=function(){this._dumped||(this._dumped=!0,this.resume())}},8419(t,e,r){var i=r(717);const n=r(4529).ok,s=r(8310),o=r(7103),a=r(537),h=a,u=r(8287).Buffer,f=r(2728),l=f.CRLF,c=f.chunkExpression,d=f.debug,p=/^Connection$/i,m=/^Transfer-Encoding$/i,g=/close/i,y=/^Content-Length$/i,b=/^Date$/i,v=/^Expect$/i,w=/^Trailer$/i,_={connection:!0,"content-length":!0,"transfer-encoding":!0,date:!0};var M;function S(){if(!M){var t=new Date;M=t.toUTCString(),o.enroll(S,1e3-t.getMilliseconds()),o._unrefActive(S)}return M}function k(){s.call(this),this.output=[],this.outputEncodings=[],this.outputCallbacks=[],this.outputSize=0,this.writable=!0,this._last=!1,this.chunkedEncoding=!1,this.shouldKeepAlive=!0,this.useChunkedEncodingByDefault=!0,this.sendDate=!1,this._removedHeader={},this._contentLength=null,this._hasBody=!0,this._trailer="",this.finished=!1,this._headerSent=!1,this.socket=null,this.connection=null,this._header=null,this._headers=null,this._headerNames={},this._onPendingData=null}function E(t,e,r,i){if(!f._checkIsHttpToken(r))throw new TypeError('Header name must be a valid HTTP Token ["'+r+'"]');if(!0===f._checkInvalidHeaderChar(i))throw new TypeError("The header content contains invalid characters");e.messageHeader+=r+": "+I(i)+l,p.test(r)?(e.sentConnectionHeader=!0,g.test(i)?t._last=!0:t.shouldKeepAlive=!0):m.test(r)?(e.sentTransferEncodingHeader=!0,c.test(i)&&(t.chunkedEncoding=!0)):y.test(r)?e.sentContentLengthHeader=!0:b.test(r)?e.sentDateHeader=!0:v.test(r)?e.sentExpect=!0:w.test(r)&&(e.sentTrailer=!0)}function x(t,e,r){t.emit("error",e),r&&r(e)}function A(t){t.uncork()}function I(t){return/[\r\n]/.test(t)?t.replace(/[\r\n]+[ \t]*/g,""):t}S._onTimeout=function(){M=void 0},a.inherits(k,s),e.OutgoingMessage=k,k.prototype.setTimeout=function(t,e){return e&&this.on("timeout",e),this.socket?this.socket.setTimeout(t):this.once("socket",function(e){e.setTimeout(t)}),this},k.prototype.destroy=function(t){this.socket?this.socket.destroy(t):this.once("socket",function(e){e.destroy(t)})},k.prototype._send=function(t,e,r){return this._headerSent||("string"==typeof t&&"hex"!==e&&"base64"!==e?t=this._header+t:(this.output.unshift(this._header),this.outputEncodings.unshift("binary"),this.outputCallbacks.unshift(null),this.outputSize+=this._header.length,"function"==typeof this._onPendingData&&this._onPendingData(this._header.length)),this._headerSent=!0),this._writeRaw(t,e,r)},k.prototype._writeRaw=function(t,e,r){"function"==typeof e&&(r=e,e=null);var n=this.connection;if(n&&n._httpMessage===this&&n.writable&&!n.destroyed){if(this.output.length>0)this._flushOutput(n);else if(0===t.length)return"function"==typeof r&&i.nextTick(r),!0;return n.write(t,e,r)}return(!n||!n.destroyed)&&this._buffer(t,e,r)},k.prototype._buffer=function(t,e,r){return this.output.push(t),this.outputEncodings.push(e),this.outputCallbacks.push(r),this.outputSize+=t.length,"function"==typeof this._onPendingData&&this._onPendingData(t.length),!1},k.prototype._storeHeader=function(t,e){var r={sentConnectionHeader:!1,sentContentLengthHeader:!1,sentTransferEncodingHeader:!1,sentDateHeader:!1,sentExpect:!1,sentTrailer:!1,messageHeader:t};if(e)for(var i,n,s=Object.keys(e),o=Array.isArray(e),a=0,h=s.length;a<h;a++){var u=s[a];if(o?(i=e[u][0],n=e[u][1]):(i=u,n=e[u]),Array.isArray(n))for(var f=0;f<n.length;f++)E(this,r,i,n[f]);else E(this,r,i,n)}!0===this.sendDate&&!1===r.sentDateHeader&&(r.messageHeader+="Date: "+S()+l);var c=this.statusCode;if(204!==c&&304!==c||!0!==this.chunkedEncoding||(d(c+" response should not use chunked encoding, closing connection."),this.chunkedEncoding=!1,this.shouldKeepAlive=!1),this._removedHeader.connection)this._last=!0,this.shouldKeepAlive=!1;else if(!1===r.sentConnectionHeader){this.shouldKeepAlive&&(r.sentContentLengthHeader||this.useChunkedEncodingByDefault||this.agent)?r.messageHeader+="Connection: keep-alive\r\n":(this._last=!0,r.messageHeader+="Connection: close\r\n")}!1===r.sentContentLengthHeader&&!1===r.sentTransferEncodingHeader&&(this._hasBody?this.useChunkedEncodingByDefault?r.sentTrailer||this._removedHeader["content-length"]||"number"!=typeof this._contentLength?this._removedHeader["transfer-encoding"]?d("Both Content-Length and Transfer-Encoding are removed"):(r.messageHeader+="Transfer-Encoding: chunked\r\n",this.chunkedEncoding=!0):r.messageHeader+="Content-Length: "+this._contentLength+"\r\n":this._last=!0:this.chunkedEncoding=!1),this._header=r.messageHeader+l,this._headerSent=!1,r.sentExpect&&this._send("")},k.prototype.setHeader=function(t,e){if(!f._checkIsHttpToken(t))throw new TypeError('Header name must be a valid HTTP Token ["'+t+'"]');if("string"!=typeof t)throw new TypeError('"name" should be a string in setHeader(name, value)');if(void 0===e)throw new Error('"value" required in setHeader("'+t+'", value)');if(this._header)throw new Error("Can't set headers after they are sent.");if(!0===f._checkInvalidHeaderChar(e))throw new TypeError("The header content contains invalid characters");null===this._headers&&(this._headers={});var r=t.toLowerCase();this._headers[r]=e,this._headerNames[r]=t,_[r]&&(this._removedHeader[r]=!1)},k.prototype.getHeader=function(t){if(arguments.length<1)throw new Error('"name" argument is required for getHeader(name)');if(this._headers){var e=t.toLowerCase();return this._headers[e]}},k.prototype.removeHeader=function(t){if(arguments.length<1)throw new Error('"name" argument is required for removeHeader(name)');if(this._header)throw new Error("Can't remove headers after they are sent");var e=t.toLowerCase();"date"===e?this.sendDate=!1:_[e]&&(this._removedHeader[e]=!0),this._headers&&(delete this._headers[e],delete this._headerNames[e])},k.prototype._renderHeaders=function(){if(this._header)throw new Error("Can't render headers after they are sent to the client");var t=this._headers;if(!t)return{};for(var e={},r=Object.keys(t),i=this._headerNames,n=0,s=r.length;n<s;n++){var o=r[n];e[i[o]]=t[o]}return e},Object.defineProperty(k.prototype,"headersSent",{configurable:!0,enumerable:!0,get:function(){return!!this._header}}),k.prototype.write=function(t,e,r){if(this.finished){var n=new Error("write after end");return i.nextTick(x,this,n,r),!0}if(this._header||this._implicitHeader(),!this._hasBody)return d("This type of response MUST NOT have a body. Ignoring write() calls."),!0;if("string"!=typeof t&&!(t instanceof u))throw new TypeError("First argument must be a string or Buffer");return 0===t.length||(this.chunkedEncoding?"string"==typeof t&&"hex"!==e&&"base64"!==e&&"binary"!==e?(t=(s=u.byteLength(t,e)).toString(16)+l+t+l,o=this._send(t,e,r)):(s="string"==typeof t?u.byteLength(t,e):t.length,this.connection&&!this.connection.corked&&(this.connection.cork(),i.nextTick(A,this.connection)),this._send(s.toString(16),"binary",null),this._send(T,null,null),this._send(t,e,null),o=this._send(T,null,r)):o=this._send(t,e,r),d("write ret = "+o),o);var s,o},k.prototype.addTrailers=function(t){this._trailer="";for(var e,r,i=Object.keys(t),n=Array.isArray(t),s=0,o=i.length;s<o;s++){var a=i[s];if(n?(e=t[a][0],r=t[a][1]):(e=a,r=t[a]),!f._checkIsHttpToken(e))throw new TypeError('Trailer name must be a valid HTTP Token ["'+e+'"]');if(!0===f._checkInvalidHeaderChar(r))throw new TypeError("The header content contains invalid characters");this._trailer+=e+": "+I(r)+l}};const T=u.from("\r\n");k.prototype.end=function(t,e,r){if("function"==typeof t?(r=t,t=null):"function"==typeof e&&(r=e,e=null),t&&"string"!=typeof t&&!(t instanceof u))throw new TypeError("First argument must be a string or Buffer");if(this.finished)return!1;var i;this._header||(this._contentLength=t?"string"==typeof t?u.byteLength(t,e):t.length:0,this._implicitHeader()),t&&!this._hasBody&&(d("This type of response MUST NOT have a body. Ignoring data passed to end()."),t=null),this.connection&&t&&this.connection.cork(),t&&this.write(t,e),"function"==typeof r&&this.once("finish",r);const n=()=>{this.emit("finish")};return i=this._hasBody&&this.chunkedEncoding?this._send("0\r\n"+this._trailer+"\r\n","binary",n):this._send("","binary",n),this.connection&&t&&this.connection.uncork(),this.finished=!0,d("outgoing message end."),0===this.output.length&&this.connection&&this.connection._httpMessage===this&&this._finish(),i},k.prototype._finish=function(){n(this.connection),this.emit("prefinish")},k.prototype._flush=function(){var t,e=this.socket;e&&e.writable&&(t=this._flushOutput(e),this.finished?this._finish():t&&this.emit("drain"))},k.prototype._flushOutput=function(t){var e,r=this.output.length;if(r<=0)return e;var i=this.output,n=this.outputEncodings,s=this.outputCallbacks;t.cork();for(var o=0;o<r;o++)e=t.write(i[o],n[o],s[o]);return t.uncork(),this.output=[],this.outputEncodings=[],this.outputCallbacks=[],"function"==typeof this._onPendingData&&this._onPendingData(-this.outputSize),this.outputSize=0,e},k.prototype.flushHeaders=function(){this._header||this._implicitHeader(),this._send("")},k.prototype.flush=h.deprecate(function(){this.flushHeaders()},"OutgoingMessage.flush is deprecated. Use flushHeaders instead.")},1678(t,e,r){const i=r(537),n=r(8957),s=r(5905).HTTPParser,o=r(4529).ok,a=r(2728),h=a.parsers,u=a.freeParser,f=a.debug,l=a.CRLF,c=a.continueExpression,d=a.chunkExpression,p=a.httpSocketSetup,m=r(8419).OutgoingMessage,g=e.STATUS_CODES={100:"Continue",101:"Switching Protocols",102:"Processing",200:"OK",201:"Created",202:"Accepted",203:"Non-Authoritative Information",204:"No Content",205:"Reset Content",206:"Partial Content",207:"Multi-Status",208:"Already Reported",226:"IM Used",300:"Multiple Choices",301:"Moved Permanently",302:"Found",303:"See Other",304:"Not Modified",305:"Use Proxy",307:"Temporary Redirect",308:"Permanent Redirect",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Payload Too Large",414:"URI Too Long",415:"Unsupported Media Type",416:"Range Not Satisfiable",417:"Expectation Failed",418:"I'm a teapot",421:"Misdirected Request",422:"Unprocessable Entity",423:"Locked",424:"Failed Dependency",425:"Unordered Collection",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Header Fields Too Large",451:"Unavailable For Legal Reasons",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Timeout",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",508:"Loop Detected",509:"Bandwidth Limit Exceeded",510:"Not Extended",511:"Network Authentication Required"},y=0|s.kOnExecute;function b(t){m.call(this),"HEAD"===t.method&&(this._hasBody=!1),this.sendDate=!0,(t.httpVersionMajor<1||t.httpVersionMinor<1)&&(this.useChunkedEncodingByDefault=d.test(t.headers.te),this.shouldKeepAlive=!1)}function v(){this._httpMessage&&this._httpMessage.emit("close")}function w(t){if(!(this instanceof w))return new w(t);n.Server.call(this,{allowHalfOpen:!0}),t&&this.addListener("request",t),this.httpAllowHalfOpen=!1,this.addListener("connection",_),this.timeout=12e4,this._pendingResponseData=0}function _(t){var e=this,r=[],i=[],n=0;function a(e){if(n+=e,t._paused&&n<t._writableState.highWaterMark)return A()}function l(){for(;i.length;){var t=i.shift();t.emit("aborted"),t.emit("close")}}function d(){f("server socket close"),this.parser&&u(this.parser,null,this),l()}f("SERVER new http connection"),p(t),e.timeout&&t.setTimeout(e.timeout),t.on("timeout",function(){var r=t.parser&&t.parser.incoming,i=r&&!r.complete&&r.emit("timeout",t),n=t._httpMessage,s=n&&n.emit("timeout",t),o=e.emit("timeout",t);i||s||o||t.destroy()});var m=h.alloc();m.reinitialize(s.REQUEST),m.socket=t,t.parser=m,m.incoming=null,"number"==typeof this.maxHeadersCount?m.maxHeaderPairs=this.maxHeadersCount<<1:m.maxHeaderPairs=2e3,t.addListener("error",v),t.addListener("close",d),m.onIncoming=function(s,h){if(i.push(s),!t._paused){(t._writableState.needDrain||n>=t._writableState.highWaterMark)&&(t._paused=!0,t.pause())}var u=new b(s);u._onPendingData=a,u.shouldKeepAlive=h,t._httpMessage?r.push(u):u.assignSocket(t);u.on("finish",function(){o(0===i.length||i[0]===s),i.shift(),s._consuming||s._readableState.resumeScheduled||s._dump();if(u.detachSocket(t),u._last)t.destroySoon();else{var e=r.shift();e&&e.assignSocket(t)}}),void 0!==s.headers.expect&&1==s.httpVersionMajor&&1==s.httpVersionMinor?c.test(s.headers.expect)?(u._expect_continue=!0,e.listenerCount("checkContinue")>0?e.emit("checkContinue",s,u):(u.writeContinue(),e.emit("request",s,u))):e.listenerCount("checkExpectation")>0?e.emit("checkExpectation",s,u):(u.writeHead(417),u.end()):e.emit("request",s,u);return!1},t.on("end",x),t.on("data",w),t.on("resume",M),t.on("pause",S),t.on("drain",A),t.on=E;var g=t._handle&&t._handle._externalStream;function v(t){this.removeListener("error",v),this.on("error",()=>{}),e.emit("clientError",t,this)||this.destroy(t)}function w(e){o(!t._paused),f("SERVER socketOnData %d",e.length),_(m.execute(e),e)}function _(r,i){if(r instanceof Error)f("parse error"),v.call(t,r);else if(m.incoming&&m.incoming.upgrade){var n=r,s=m.incoming;f("SERVER upgrade or connect",s.method),i||(i=m.getCurrentBuffer()),t.removeListener("data",w),t.removeListener("end",x),t.removeListener("close",d),k(m,t),m.finish(),u(m,s,null),m=null;var o="CONNECT"===s.method?"connect":"upgrade";if(e.listenerCount(o)>0){f("SERVER have listener for %s",o);var a=i.slice(n,i.length);t._readableState.flowing=null,e.emit(o,s,t,a)}else t.destroy()}t._paused&&t.parser&&(f("pause parser"),t.parser.pause())}function x(){var t=this,i=m.finish();if(i instanceof Error)return f("parse error"),void v.call(t,i);e.httpAllowHalfOpen?r.length?r[r.length-1]._last=!0:t._httpMessage?t._httpMessage._last=!0:t.writable&&t.end():(l(),t.writable&&t.end())}function A(){var e=n>t._writableState.highWaterMark;t._paused&&!e&&(t._paused=!1,t.parser&&t.parser.resume(),t.resume())}g&&(m._consumed=!0,m.consume(g)),g=null,m[y]=function(e,r){t._unrefTimer(),f("SERVER socketOnParserExecute %d",e),_(e,void 0)},t._paused=!1}function M(){this._paused?this.pause():this._handle&&!this._handle.reading&&(this._handle.reading=!0,this._handle.readStart())}function S(){this._handle&&this._handle.reading&&(this._handle.reading=!1,this._handle.readStop())}function k(t,e){e._handle&&(t._consumed&&t.unconsume(e._handle._externalStream),t._consumed=!1,e.removeListener("pause",S),e.removeListener("resume",M))}function E(t,e){var r=n.Socket.prototype.on.call(this,t,e);return this.parser?("data"!==t&&"readable"!==t||k(this.parser,this),r):(this.on=n.Socket.prototype.on,r)}i.inherits(b,m),b.prototype._finish=function(){m.prototype._finish.call(this)},e.ServerResponse=b,b.prototype.statusCode=200,b.prototype.statusMessage=void 0,b.prototype.assignSocket=function(t){o(!t._httpMessage),t._httpMessage=this,t.on("close",v),this.socket=t,this.connection=t,this.emit("socket",t),this._flush()},b.prototype.detachSocket=function(t){o(t._httpMessage===this),t.removeListener("close",v),t._httpMessage=null,this.socket=this.connection=null},b.prototype.writeContinue=function(t){this._writeRaw("HTTP/1.1 100 Continue"+l+l,"ascii",t),this._sent100=!0},b.prototype._implicitHeader=function(){this.writeHead(this.statusCode)},b.prototype.writeHead=function(t,e,r){var i;if("string"==typeof e?this.statusMessage=e:(this.statusMessage=this.statusMessage||g[t]||"unknown",r=e),this.statusCode=t,this._headers){if(r)for(var n=Object.keys(r),s=0;s<n.length;s++){var o=n[s];o&&this.setHeader(o,r[o])}i=this._renderHeaders()}else i=r;if((t|=0)<100||t>999)throw new RangeError(`Invalid status code: ${t}`);var a="HTTP/1.1 "+t.toString()+" "+this.statusMessage+l;(204===t||304===t||100<=t&&t<=199)&&(this._hasBody=!1),this._expect_continue&&!this._sent100&&(this.shouldKeepAlive=!1),this._storeHeader(a,i)},b.prototype.writeHeader=function(){this.writeHead.apply(this,arguments)},i.inherits(w,n.Server),w.prototype.setTimeout=function(t,e){return this.timeout=t,e&&this.on("timeout",e),this},e.Server=w,e._connectionListener=_},2195(t,e,r){const i=r(537),n=i,s=r(7007);e.IncomingMessage=r(3989).IncomingMessage;const o=r(2728);e.METHODS=o.methods.slice().sort(),e.OutgoingMessage=r(8419).OutgoingMessage;const a=r(1678);e.ServerResponse=a.ServerResponse,e.STATUS_CODES=a.STATUS_CODES;const h=r(8748),u=e.Agent=h.Agent;e.globalAgent=h.globalAgent;const f=r(5930),l=e.ClientRequest=f.ClientRequest;e.request=function(t,e){return new l(t,e)},e.get=function(t,r){var i=e.request(t,r);return i.end(),i},e._connectionListener=a._connectionListener;const c=e.Server=a.Server;function d(t,e){if(!(this instanceof d))return new d(t,e);s.call(this),e=e||"localhost",t=t||80,this.host=e,this.port=t,this.agent=new u({host:e,port:t,maxSockets:1})}e.createServer=function(t){return new c(t)},i.inherits(d,s),d.prototype.request=function(t,e,r){var i=this,n={};n.host=i.host,n.port=i.port,"/"===t[0]&&(r=e,e=t,t="GET"),n.method=t,n.path=e,n.headers=r,n.agent=i.agent;var s=new l(n);return s.on("error",function(t){i.emit("error",t)}),s.on("socket",function(t){t.on("end",function(){if(i._decoder){var t=i._decoder.end();t&&i.emit("data",t)}i.emit("end")})}),s},e.Client=n.deprecate(d,"http.Client is deprecated."),e.createClient=n.deprecate(function(t,e){return new d(t,e)},"http.createClient is deprecated. Use http.request instead.")},7568(t,e,r){var i=e;i.bignum=r(2344),i.define=r(7363).define,i.base=r(9673),i.constants=r(2153),i.decoders=r(2853),i.encoders=r(4669)},7363(t,e,r){var i=r(7568),n=r(6698);function s(t,e){this.name=t,this.body=e,this.decoders={},this.encoders={}}e.define=function(t,e){return new s(t,e)},s.prototype._createNamed=function(t){var e;try{e=Object(function(){var t=new Error("Cannot find module 'vm'");throw t.code="MODULE_NOT_FOUND",t}())("(function "+this.name+"(entity) {\n this._initNamed(entity);\n})")}catch(t){e=function(t){this._initNamed(t)}}return n(e,t),e.prototype._initNamed=function(e){t.call(this,e)},new e(this)},s.prototype._getDecoder=function(t){return t=t||"der",this.decoders.hasOwnProperty(t)||(this.decoders[t]=this._createNamed(i.decoders[t])),this.decoders[t]},s.prototype.decode=function(t,e,r){return this._getDecoder(e).decode(t,r)},s.prototype._getEncoder=function(t){return t=t||"der",this.encoders.hasOwnProperty(t)||(this.encoders[t]=this._createNamed(i.encoders[t])),this.encoders[t]},s.prototype.encode=function(t,e,r){return this._getEncoder(e).encode(t,r)}},7227(t,e,r){var i=r(6698),n=r(9673).Reporter,s=r(8287).Buffer;function o(t,e){n.call(this,e),s.isBuffer(t)?(this.base=t,this.offset=0,this.length=t.length):this.error("Input not Buffer")}function a(t,e){if(Array.isArray(t))this.length=0,this.value=t.map(function(t){return t instanceof a||(t=new a(t,e)),this.length+=t.length,t},this);else if("number"==typeof t){if(!(0<=t&&t<=255))return e.error("non-byte EncoderBuffer value");this.value=t,this.length=1}else if("string"==typeof t)this.value=t,this.length=s.byteLength(t);else{if(!s.isBuffer(t))return e.error("Unsupported type: "+typeof t);this.value=t,this.length=t.length}}i(o,n),e.t=o,o.prototype.save=function(){return{offset:this.offset,reporter:n.prototype.save.call(this)}},o.prototype.restore=function(t){var e=new o(this.base);return e.offset=t.offset,e.length=this.offset,this.offset=t.offset,n.prototype.restore.call(this,t.reporter),e},o.prototype.isEmpty=function(){return this.offset===this.length},o.prototype.readUInt8=function(t){return this.offset+1<=this.length?this.base.readUInt8(this.offset++,!0):this.error(t||"DecoderBuffer overrun")},o.prototype.skip=function(t,e){if(!(this.offset+t<=this.length))return this.error(e||"DecoderBuffer overrun");var r=new o(this.base);return r._reporterState=this._reporterState,r.offset=this.offset,r.length=this.offset+t,this.offset+=t,r},o.prototype.raw=function(t){return this.base.slice(t?t.offset:this.offset,this.length)},e.d=a,a.prototype.join=function(t,e){return t||(t=new s(this.length)),e||(e=0),0===this.length||(Array.isArray(this.value)?this.value.forEach(function(r){r.join(t,e),e+=r.length}):("number"==typeof this.value?t[e]=this.value:"string"==typeof this.value?t.write(this.value,e):s.isBuffer(this.value)&&this.value.copy(t,e),e+=this.length)),t}},9673(t,e,r){var i=e;i.Reporter=r(9220).a,i.DecoderBuffer=r(7227).t,i.EncoderBuffer=r(7227).d,i.Node=r(993)},993(t,e,r){var i=r(9673).Reporter,n=r(9673).EncoderBuffer,s=r(9673).DecoderBuffer,o=r(3349),a=["seq","seqof","set","setof","objid","bool","gentime","utctime","null_","enum","int","objDesc","bitstr","bmpstr","charstr","genstr","graphstr","ia5str","iso646str","numstr","octstr","printstr","t61str","unistr","utf8str","videostr"],h=["key","obj","use","optional","explicit","implicit","def","choice","any","contains"].concat(a);function u(t,e){var r={};this._baseState=r,r.enc=t,r.parent=e||null,r.children=null,r.tag=null,r.args=null,r.reverseArgs=null,r.choice=null,r.optional=!1,r.any=!1,r.obj=!1,r.use=null,r.useDecoder=null,r.key=null,r.default=null,r.explicit=null,r.implicit=null,r.contains=null,r.parent||(r.children=[],this._wrap())}t.exports=u;var f=["enc","parent","children","tag","args","reverseArgs","choice","optional","any","obj","use","alteredUse","key","default","explicit","implicit","contains"];u.prototype.clone=function(){var t=this._baseState,e={};f.forEach(function(r){e[r]=t[r]});var r=new this.constructor(e.parent);return r._baseState=e,r},u.prototype._wrap=function(){var t=this._baseState;h.forEach(function(e){this[e]=function(){var r=new this.constructor(this);return t.children.push(r),r[e].apply(r,arguments)}},this)},u.prototype._init=function(t){var e=this._baseState;o(null===e.parent),t.call(this),e.children=e.children.filter(function(t){return t._baseState.parent===this},this),o.equal(e.children.length,1,"Root node can have only one child")},u.prototype._useArgs=function(t){var e=this._baseState,r=t.filter(function(t){return t instanceof this.constructor},this);t=t.filter(function(t){return!(t instanceof this.constructor)},this),0!==r.length&&(o(null===e.children),e.children=r,r.forEach(function(t){t._baseState.parent=this},this)),0!==t.length&&(o(null===e.args),e.args=t,e.reverseArgs=t.map(function(t){if("object"!=typeof t||t.constructor!==Object)return t;var e={};return Object.keys(t).forEach(function(r){r==(0|r)&&(r|=0);var i=t[r];e[i]=r}),e}))},["_peekTag","_decodeTag","_use","_decodeStr","_decodeObjid","_decodeTime","_decodeNull","_decodeInt","_decodeBool","_decodeList","_encodeComposite","_encodeStr","_encodeObjid","_encodeTime","_encodeNull","_encodeInt","_encodeBool"].forEach(function(t){u.prototype[t]=function(){var e=this._baseState;throw new Error(t+" not implemented for encoding: "+e.enc)}}),a.forEach(function(t){u.prototype[t]=function(){var e=this._baseState,r=Array.prototype.slice.call(arguments);return o(null===e.tag),e.tag=t,this._useArgs(r),this}}),u.prototype.use=function(t){o(t);var e=this._baseState;return o(null===e.use),e.use=t,this},u.prototype.optional=function(){return this._baseState.optional=!0,this},u.prototype.def=function(t){var e=this._baseState;return o(null===e.default),e.default=t,e.optional=!0,this},u.prototype.explicit=function(t){var e=this._baseState;return o(null===e.explicit&&null===e.implicit),e.explicit=t,this},u.prototype.implicit=function(t){var e=this._baseState;return o(null===e.explicit&&null===e.implicit),e.implicit=t,this},u.prototype.obj=function(){var t=this._baseState,e=Array.prototype.slice.call(arguments);return t.obj=!0,0!==e.length&&this._useArgs(e),this},u.prototype.key=function(t){var e=this._baseState;return o(null===e.key),e.key=t,this},u.prototype.any=function(){return this._baseState.any=!0,this},u.prototype.choice=function(t){var e=this._baseState;return o(null===e.choice),e.choice=t,this._useArgs(Object.keys(t).map(function(e){return t[e]})),this},u.prototype.contains=function(t){var e=this._baseState;return o(null===e.use),e.contains=t,this},u.prototype._decode=function(t,e){var r=this._baseState;if(null===r.parent)return t.wrapResult(r.children[0]._decode(t,e));var i,n=r.default,o=!0,a=null;if(null!==r.key&&(a=t.enterKey(r.key)),r.optional){var h=null;if(null!==r.explicit?h=r.explicit:null!==r.implicit?h=r.implicit:null!==r.tag&&(h=r.tag),null!==h||r.any){if(o=this._peekTag(t,h,r.any),t.isError(o))return o}else{var u=t.save();try{null===r.choice?this._decodeGeneric(r.tag,t,e):this._decodeChoice(t,e),o=!0}catch(t){o=!1}t.restore(u)}}if(r.obj&&o&&(i=t.enterObject()),o){if(null!==r.explicit){var f=this._decodeTag(t,r.explicit);if(t.isError(f))return f;t=f}var l=t.offset;if(null===r.use&&null===r.choice){if(r.any)u=t.save();var c=this._decodeTag(t,null!==r.implicit?r.implicit:r.tag,r.any);if(t.isError(c))return c;r.any?n=t.raw(u):t=c}if(e&&e.track&&null!==r.tag&&e.track(t.path(),l,t.length,"tagged"),e&&e.track&&null!==r.tag&&e.track(t.path(),t.offset,t.length,"content"),r.any||(n=null===r.choice?this._decodeGeneric(r.tag,t,e):this._decodeChoice(t,e)),t.isError(n))return n;if(r.any||null!==r.choice||null===r.children||r.children.forEach(function(r){r._decode(t,e)}),r.contains&&("octstr"===r.tag||"bitstr"===r.tag)){var d=new s(n);n=this._getUse(r.contains,t._reporterState.obj)._decode(d,e)}}return r.obj&&o&&(n=t.leaveObject(i)),null===r.key||null===n&&!0!==o?null!==a&&t.exitKey(a):t.leaveKey(a,r.key,n),n},u.prototype._decodeGeneric=function(t,e,r){var i=this._baseState;return"seq"===t||"set"===t?null:"seqof"===t||"setof"===t?this._decodeList(e,t,i.args[0],r):/str$/.test(t)?this._decodeStr(e,t,r):"objid"===t&&i.args?this._decodeObjid(e,i.args[0],i.args[1],r):"objid"===t?this._decodeObjid(e,null,null,r):"gentime"===t||"utctime"===t?this._decodeTime(e,t,r):"null_"===t?this._decodeNull(e,r):"bool"===t?this._decodeBool(e,r):"objDesc"===t?this._decodeStr(e,t,r):"int"===t||"enum"===t?this._decodeInt(e,i.args&&i.args[0],r):null!==i.use?this._getUse(i.use,e._reporterState.obj)._decode(e,r):e.error("unknown tag: "+t)},u.prototype._getUse=function(t,e){var r=this._baseState;return r.useDecoder=this._use(t,e),o(null===r.useDecoder._baseState.parent),r.useDecoder=r.useDecoder._baseState.children[0],r.implicit!==r.useDecoder._baseState.implicit&&(r.useDecoder=r.useDecoder.clone(),r.useDecoder._baseState.implicit=r.implicit),r.useDecoder},u.prototype._decodeChoice=function(t,e){var r=this._baseState,i=null,n=!1;return Object.keys(r.choice).some(function(s){var o=t.save(),a=r.choice[s];try{var h=a._decode(t,e);if(t.isError(h))return!1;i={type:s,value:h},n=!0}catch(e){return t.restore(o),!1}return!0},this),n?i:t.error("Choice not matched")},u.prototype._createEncoderBuffer=function(t){return new n(t,this.reporter)},u.prototype._encode=function(t,e,r){var i=this._baseState;if(null===i.default||i.default!==t){var n=this._encodeValue(t,e,r);if(void 0!==n&&!this._skipDefault(n,e,r))return n}},u.prototype._encodeValue=function(t,e,r){var n=this._baseState;if(null===n.parent)return n.children[0]._encode(t,e||new i);var s=null;if(this.reporter=e,n.optional&&void 0===t){if(null===n.default)return;t=n.default}var o=null,a=!1;if(n.any)s=this._createEncoderBuffer(t);else if(n.choice)s=this._encodeChoice(t,e);else if(n.contains)o=this._getUse(n.contains,r)._encode(t,e),a=!0;else if(n.children)o=n.children.map(function(r){if("null_"===r._baseState.tag)return r._encode(null,e,t);if(null===r._baseState.key)return e.error("Child should have a key");var i=e.enterKey(r._baseState.key);if("object"!=typeof t)return e.error("Child expected, but input is not object");var n=r._encode(t[r._baseState.key],e,t);return e.leaveKey(i),n},this).filter(function(t){return t}),o=this._createEncoderBuffer(o);else if("seqof"===n.tag||"setof"===n.tag){if(!n.args||1!==n.args.length)return e.error("Too many args for : "+n.tag);if(!Array.isArray(t))return e.error("seqof/setof, but data is not Array");var h=this.clone();h._baseState.implicit=null,o=this._createEncoderBuffer(t.map(function(r){var i=this._baseState;return this._getUse(i.args[0],t)._encode(r,e)},h))}else null!==n.use?s=this._getUse(n.use,r)._encode(t,e):(o=this._encodePrimitive(n.tag,t),a=!0);if(!n.any&&null===n.choice){var u=null!==n.implicit?n.implicit:n.tag,f=null===n.implicit?"universal":"context";null===u?null===n.use&&e.error("Tag could be omitted only for .use()"):null===n.use&&(s=this._encodeComposite(u,a,f,o))}return null!==n.explicit&&(s=this._encodeComposite(n.explicit,!1,"context",s)),s},u.prototype._encodeChoice=function(t,e){var r=this._baseState,i=r.choice[t.type];return i||o(!1,t.type+" not found in "+JSON.stringify(Object.keys(r.choice))),i._encode(t.value,e)},u.prototype._encodePrimitive=function(t,e){var r=this._baseState;if(/str$/.test(t))return this._encodeStr(e,t);if("objid"===t&&r.args)return this._encodeObjid(e,r.reverseArgs[0],r.args[1]);if("objid"===t)return this._encodeObjid(e,null,null);if("gentime"===t||"utctime"===t)return this._encodeTime(e,t);if("null_"===t)return this._encodeNull();if("int"===t||"enum"===t)return this._encodeInt(e,r.args&&r.reverseArgs[0]);if("bool"===t)return this._encodeBool(e);if("objDesc"===t)return this._encodeStr(e,t);throw new Error("Unsupported tag: "+t)},u.prototype._isNumstr=function(t){return/^[0-9 ]*$/.test(t)},u.prototype._isPrintstr=function(t){return/^[A-Za-z0-9 '\(\)\+,\-\.\/:=\?]*$/.test(t)}},9220(t,e,r){var i=r(6698);function n(t){this._reporterState={obj:null,path:[],options:t||{},errors:[]}}function s(t,e){this.path=t,this.rethrow(e)}e.a=n,n.prototype.isError=function(t){return t instanceof s},n.prototype.save=function(){var t=this._reporterState;return{obj:t.obj,pathLen:t.path.length}},n.prototype.restore=function(t){var e=this._reporterState;e.obj=t.obj,e.path=e.path.slice(0,t.pathLen)},n.prototype.enterKey=function(t){return this._reporterState.path.push(t)},n.prototype.exitKey=function(t){var e=this._reporterState;e.path=e.path.slice(0,t-1)},n.prototype.leaveKey=function(t,e,r){var i=this._reporterState;this.exitKey(t),null!==i.obj&&(i.obj[e]=r)},n.prototype.path=function(){return this._reporterState.path.join("/")},n.prototype.enterObject=function(){var t=this._reporterState,e=t.obj;return t.obj={},e},n.prototype.leaveObject=function(t){var e=this._reporterState,r=e.obj;return e.obj=t,r},n.prototype.error=function(t){var e,r=this._reporterState,i=t instanceof s;if(e=i?t:new s(r.path.map(function(t){return"["+JSON.stringify(t)+"]"}).join(""),t.message||t,t.stack),!r.options.partial)throw e;return i||r.errors.push(e),e},n.prototype.wrapResult=function(t){var e=this._reporterState;return e.options.partial?{result:this.isError(t)?null:t,errors:e.errors}:t},i(s,Error),s.prototype.rethrow=function(t){if(this.message=t+" at: "+(this.path||"(shallow)"),Error.captureStackTrace&&Error.captureStackTrace(this,s),!this.stack)try{throw new Error(this.message)}catch(t){this.stack=t.stack}return this}},4598(t,e,r){var i=r(2153);e.tagClass={0:"universal",1:"application",2:"context",3:"private"},e.tagClassByName=i._reverse(e.tagClass),e.tag={0:"end",1:"bool",2:"int",3:"bitstr",4:"octstr",5:"null_",6:"objid",7:"objDesc",8:"external",9:"real",10:"enum",11:"embed",12:"utf8str",13:"relativeOid",16:"seq",17:"set",18:"numstr",19:"printstr",20:"t61str",21:"videostr",22:"ia5str",23:"utctime",24:"gentime",25:"graphstr",26:"iso646str",27:"genstr",28:"unistr",29:"charstr",30:"bmpstr"},e.tagByName=i._reverse(e.tag)},2153(t,e,r){var i=e;i._reverse=function(t){var e={};return Object.keys(t).forEach(function(r){(0|r)==r&&(r|=0);var i=t[r];e[i]=r}),e},i.der=r(4598)},2010(t,e,r){var i=r(6698),n=r(7568),s=n.base,o=n.bignum,a=n.constants.der;function h(t){this.enc="der",this.name=t.name,this.entity=t,this.tree=new u,this.tree._init(t.body)}function u(t){s.Node.call(this,"der",t)}function f(t,e){var r=t.readUInt8(e);if(t.isError(r))return r;var i=a.tagClass[r>>6],n=!(32&r);if(31&~r)r&=31;else{var s=r;for(r=0;!(128&~s);){if(s=t.readUInt8(e),t.isError(s))return s;r<<=7,r|=127&s}}return{cls:i,primitive:n,tag:r,tagStr:a.tag[r]}}function l(t,e,r){var i=t.readUInt8(r);if(t.isError(i))return i;if(!e&&128===i)return null;if(!(128&i))return i;var n=127&i;if(n>4)return t.error("length octect is too long");i=0;for(var s=0;s<n;s++){i<<=8;var o=t.readUInt8(r);if(t.isError(o))return o;i|=o}return i}t.exports=h,h.prototype.decode=function(t,e){return t instanceof s.DecoderBuffer||(t=new s.DecoderBuffer(t,e)),this.tree._decode(t,e)},i(u,s.Node),u.prototype._peekTag=function(t,e,r){if(t.isEmpty())return!1;var i=t.save(),n=f(t,'Failed to peek tag: "'+e+'"');return t.isError(n)?n:(t.restore(i),n.tag===e||n.tagStr===e||n.tagStr+"of"===e||r)},u.prototype._decodeTag=function(t,e,r){var i=f(t,'Failed to decode tag of "'+e+'"');if(t.isError(i))return i;var n=l(t,i.primitive,'Failed to get length of "'+e+'"');if(t.isError(n))return n;if(!r&&i.tag!==e&&i.tagStr!==e&&i.tagStr+"of"!==e)return t.error('Failed to match tag: "'+e+'"');if(i.primitive||null!==n)return t.skip(n,'Failed to match body of: "'+e+'"');var s=t.save(),o=this._skipUntilEnd(t,'Failed to skip indefinite length body: "'+this.tag+'"');return t.isError(o)?o:(n=t.offset-s.offset,t.restore(s),t.skip(n,'Failed to match body of: "'+e+'"'))},u.prototype._skipUntilEnd=function(t,e){for(;;){var r=f(t,e);if(t.isError(r))return r;var i,n=l(t,r.primitive,e);if(t.isError(n))return n;if(i=r.primitive||null!==n?t.skip(n):this._skipUntilEnd(t,e),t.isError(i))return i;if("end"===r.tagStr)break}},u.prototype._decodeList=function(t,e,r,i){for(var n=[];!t.isEmpty();){var s=this._peekTag(t,"end");if(t.isError(s))return s;var o=r.decode(t,"der",i);if(t.isError(o)&&s)break;n.push(o)}return n},u.prototype._decodeStr=function(t,e){if("bitstr"===e){var r=t.readUInt8();return t.isError(r)?r:{unused:r,data:t.raw()}}if("bmpstr"===e){var i=t.raw();if(i.length%2==1)return t.error("Decoding of string type: bmpstr length mismatch");for(var n="",s=0;s<i.length/2;s++)n+=String.fromCharCode(i.readUInt16BE(2*s));return n}if("numstr"===e){var o=t.raw().toString("ascii");return this._isNumstr(o)?o:t.error("Decoding of string type: numstr unsupported characters")}if("octstr"===e)return t.raw();if("objDesc"===e)return t.raw();if("printstr"===e){var a=t.raw().toString("ascii");return this._isPrintstr(a)?a:t.error("Decoding of string type: printstr unsupported characters")}return/str$/.test(e)?t.raw().toString():t.error("Decoding of string type: "+e+" unsupported")},u.prototype._decodeObjid=function(t,e,r){for(var i,n=[],s=0;!t.isEmpty();){var o=t.readUInt8();s<<=7,s|=127&o,128&o||(n.push(s),s=0)}128&o&&n.push(s)