/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/siege@0.2.0/siege.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
var util=require("util"),child_process=require("child_process"),http=require("http"),path=require("path"),fs=require("fs"),siege_attack=require("./siege_attack"),__slice=Array.prototype.slice,Siege=function(t,e){e||("object"==typeof t?(e=t,t=void 0):e={}),t&&(e.serve=t),e.tasks=[],this.tasks=[],this.options=e,this.current_task=null;var i=this;this.__defineGetter__("withCookie",(function(){return i.options.enableCookie=!0,i})),this.__defineGetter__("with304",(function(){return i.options.enable304=!0,i})),this.__defineGetter__("withoutCookie",(function(){return i.options.enableCookie=!1,i})),this.__defineGetter__("without304",(function(){return i.options.enable304=!1,i}))},siege=Siege.prototype;function SiegeWrap(t){this.siege=t}siege.on=function(t){return/\d+/.test(t)?this.options.port=t:this.options.sockpath=t,this},siege.host=function(t){return this.options.host=t,this},siege.hostname=function(t){return this.options.hostname=t,this},siege.rejectUnauthorized=function(t){return this.options.rejectUnauthorized=t,this},siege.requestCert=function(t){return this.options.requestCert=t,this},siege.agent=function(t){return this.options.agent=t,this},siege.sslProtocol=function(t){return this.options.sslProtocol=t,this},siege.concurrent=function(t){return this.options.concurrent=t,this},siege.describe=function(t){var e=this.current_task;return e&&!e.options.description||(e=this._newtask()),e.options.description=t,e},siege.wait=function(t){return this.options.wait=t,this},siege._newtask=function(){var t=new Task(this);return this.tasks.push(t),this.current_task=t,t},siege.request=function(t){var e=this.current_task;return e&&!e.options.method||(e=this._newtask()),e.request(t),e},siege.get=function(t,e){return this.request({path:t,method:"GET",query:e})},siege.post=function(t,e){return this.request({path:t,method:"POST",body:e})},siege.set=function(t,e){return this.options.headers=this.options.headers||{},this.options.headers[t]=e,this},siege.for=function(t){return new For(this,t)},siege.report=function(t){return this.options.report=t,this},siege.attack=function(){var t=this.options;this.tasks.forEach((function(e){t.tasks.push(e.options)})),t.port||t.sockpath||(t.sockpath="/tmp/siege.sock"),queueSiege(this.options)};var wrap=SiegeWrap.prototype;function Task(t){this.siege=t,this.options={};var e=this;this.__defineGetter__("withCookie",(function(){return e.options.enableCookie=!0,e})),this.__defineGetter__("with304",(function(){return e.options.enable304=!0,e})),this.__defineGetter__("withoutCookie",(function(){return e.options.enableCookie=!1,e})),this.__defineGetter__("without304",(function(){return e.options.enable304=!1,e}))}["request","get","post","attack","describe"].forEach((function(t){"_"!=t[0]&&(wrap[t]=function(){var e=__slice.call(arguments);return siege[t].apply(this.siege,e)})})),util.inherits(Task,SiegeWrap);var task=Task.prototype;function For(t,e){this.__defineGetter__("seconds",(function(){return t.options.duration=1e3*e,t})),this.__defineGetter__("times",(function(){return t.options.repeat=e,t}))}function merge(t,e){for(var i in e)t[i]=e[i]}task.for=function(t){return new For(this,t)},task.request=function(t){t.method=t.method||"GET",merge(this.options,t)},task.concurrent=function(t){return this.options.concurrent=t,this},task.report=function(t){this.options.report=t};var queue=[],started=!1;function queueSiege(t){queue.push(t),started||(started=!0,nextSiege())}function nextSiege(){var t=queue.shift();t||process.exit(),startSiege(t,nextSiege)}function startSiege(t,e){startServe(t,(function(i){t.taskIndex=-1;var s=siege_attack(t,r);function r(){i&&i.kill(),s.halt(),e()}process.on("SIGINT",r),process.on("uncaughtException",(function(t){console.log(t.stack),r()}))}))}function startServe(t,e){var i=t.serve;if(!i)return e();console.log("starting "+i);var s=i,r=[];try{require(i),s="node",r=[__dirname+"/siege_server.js","--port",t.sockpath||t.port||"/tmp/siege.sock",i]}catch(t){r=(s=s.split(/\s+/g)).slice(1),s=s[0]}var o=child_process.spawn(s,r),n=path.join(process.cwd(),t.serverlog||"server.log");path.join(process.cwd(),t.servererrlog||"server.error.log");o.stdout.pipe(fs.createWriteStream(n)),o.stderr.pipe(process.stderr);var u=t.wait||200;process.stdout.write("[?25l");var c=setInterval((function(){process.stdout.write(".")}),u/30);setTimeout((function(){clearInterval(c),process.stdout.write("\r[K"),e(o)}),u)}var exports=module.exports=function(t,e){return new Siege(t,e)};
//# sourceMappingURL=/sm/3b0163bb079c129a8f1ced49c29cb1beee917444ba4841298587e00f6c5da105.map