varF=t,M=s,q=r.spawn,W=V;functionV(e){e=e||{};vart,s,r=this,o=i,a=n,h={},c=!1,l={"User-Agent":"node-XMLHttpRequest",Accept:"*/*"},d=Object.assign({},l),p=["accept-charset","accept-encoding","access-control-request-headers","access-control-request-method","connection","content-length","content-transfer-encoding","cookie","cookie2","date","expect","host","keep-alive","origin","referer","te","trailer","transfer-encoding","upgrade","via"],u=["TRACE","TRACK","CONNECT"],f=!1,_=!1,m=!1,y={};this.UNSENT=0,this.OPENED=1,this.HEADERS_RECEIVED=2,this.LOADING=3,this.DONE=4,this.readyState=this.UNSENT,this.onreadystatechange=null,this.responseText="",this.responseXML="",this.status=null,this.statusText=null;this.open=function(e,t,s,r,i){if(this.abort(),_=!1,m=!1,!function(e){returne&&-1===u.indexOf(e)}(e))thrownewError("SecurityError: Request method not allowed");h={method:e,url:t.toString(),async:"boolean"!=typeofs||s,user:r||null,password:i||null},g(this.OPENED)},this.setDisableHeaderCheck=function(e){c=e},this.setRequestHeader=function(e,t){if(this.readyState!=this.OPENED)thrownewError("INVALID_STATE_ERR: setRequestHeader can only be called when state is OPEN");if(!function(e){returnc||e&&-1===p.indexOf(e.toLowerCase())}(e))returnconsole.warn('Refused to set unsafe header "'+e+'"'),!1;if(f)thrownewError("INVALID_STATE_ERR: send flag is true");returnd[e]=t,!0},this.getResponseHeader=function(e){return"string"==typeofe&&this.readyState>this.OPENED&&s.headers[e.toLowerCase()]&&!_?s.headers[e.toLowerCase()]:null},this.getAllResponseHeaders=function(){if(this.readyState<this.HEADERS_RECEIVED||_)return"";vare="";for(vartins.headers)"set-cookie"!==t&&"set-cookie2"!==t&&(e+=t+": "+s.headers[t]+"\r\n");returne.substr(0,e.length-2)},this.getRequestHeader=function(e){return"string"==typeofe&&d[e]?d[e]:""},this.send=function(i){if(this.readyState!=this.OPENED)thrownewError("INVALID_STATE_ERR: connection must be opened before send() is called");if(f)thrownewError("INVALID_STATE_ERR: send has already been called");varn,c=!1,l=!1,p=M.parse(h.url);switch(p.protocol){case"https:":c=!0;case"http:":n=p.hostname;break;case"file:":l=!0;break;casevoid0:case"":n="localhost";break;default:thrownewError("Protocol not supported.")}if(l){if("GET"!==h.method)thrownewError("XMLHttpRequest: Only GET method is supported");if(h.async)F.readFile(unescape(p.pathname),"utf8",(function(e,t){e?r.handleError(e,e.errno||-1):(r.status=200,r.responseText=t,g(r.DONE))}));elsetry{this.responseText=F.readFileSync(unescape(p.pathname),"utf8"),this.status=200,g(r.DONE)}catch(e){this.handleError(e,e.errno||-1)}}else{varu=p.port||(c?443:80),m=p.pathname+(p.search?p.search:"");if(d.Host=n,c&&443===u||80===u||(d.Host+=":"+p.port),h.user){void0===h.password&&(h.password="");vary=newBuffer(h.user+":"+h.password);d.Authorization="Basic "+y.toString("base64")}"GET"===h.method||"HEAD"===h.method?i=null:i?(d["Content-Length"]=Buffer.isBuffer(i)?i.length:Buffer.byteLength(i),d["Content-Type"]||(d["Content-Type"]="text/plain;charset=UTF-8")):"POST"===h.method&&(d["Content-Length"]=0);varb=e.agent||!1,v={host:n,port:u,path:m,method:h.method,headers:d,agent:b};if(c&&(v.pfx=e.pfx,v.key=e.key,v.passphrase=e.passphrase,v.cert=e.cert,v.ca=e.ca,v.ciphers=e.ciphers,v.rejectUnauthorized=!1!==e.rejectUnauthorized),_=!1,h.async){varE=c?a.request:o.request;f=!0,r.dispatchEvent("readystatechange");varw=function(i){if(302===(s=i).statusCode||303===s.statusCode||307===s.statusCode){h.url=s.headers.location;varo=M.parse(h.url);n=o.hostname;vara={hostname:o.hostname,port:o.port,path:o.path,method:303===s.statusCode?"GET":h.method,headers:d};returnc&&(a.pfx=e.pfx,a.key=e.key,a.passphrase=e.passphrase,a.cert=e.cert,a.ca=e.ca,a.ciphers=e.ciphers,a.rejectUnauthorized=!1!==e.rejectUnauthorized),void(t=E(a,w).on("error",S)).end()}s&&s.setEncoding&&s.setEncoding("utf8"),g(r.HEADERS_RECEIVED),r.status=s.statusCode,s.on("data",(function(e){e&&(r.responseText+=e),f&&g(r.LOADING)})),s.on("end",(function(){f&&(f=!1,g(r.DONE))})),s.on("error",(function(e){r.handleError(e)})