// @bun
import{MG as V,PG as P}from"./chunk-xyhgvt88.js";var Y=V((G)=>{var M=G&&G.__createBinding||(Object.create?function(w,y,z,C){if(C===void 0)C=z;var F=Object.getOwnPropertyDescriptor(y,z);if(!F||("get"in F?!y.__esModule:F.writable||F.configurable))F={enumerable:!0,get:function(){return y[z]}};Object.defineProperty(w,C,F)}:function(w,y,z,C){if(C===void 0)C=z;w[C]=y[z]}),j=G&&G.__setModuleDefault||(Object.create?function(w,y){Object.defineProperty(w,"default",{enumerable:!0,value:y})}:function(w,y){w.default=y}),W=G&&G.__importStar||function(w){if(w&&w.__esModule)return w;var y={};if(w!=null){for(var z in w)if(z!=="default"&&Object.prototype.hasOwnProperty.call(w,z))M(y,w,z)}return j(y,w),y};Object.defineProperty(G,"__esModule",{value:!0});G.req=G.json=G.toBuffer=void 0;var B=W(P("http")),b=W(P("https"));async function X(w){let y=0,z=[];for await(let C of w)y+=C.length,z.push(C);return Buffer.concat(z,y)}G.toBuffer=X;async function g(w){let z=(await X(w)).toString("utf8");try{return JSON.parse(z)}catch(C){let F=C;throw F.message+=` (input: ${z})`,F}}G.json=g;function S(w,y={}){let C=((typeof w==="string"?w:w.href).startsWith("https:")?b:B).request(w,y),F=new Promise((Q,K)=>{C.once("response",Q).once("error",K).end()});return C.then=F.then.bind(F),C}G.req=S});var T=V((H)=>{var $=H&&H.__createBinding||(Object.create?function(w,y,z,C){if(C===void 0)C=z;var F=Object.getOwnPropertyDescriptor(y,z);if(!F||("get"in F?!y.__esModule:F.writable||F.configurable))F={enumerable:!0,get:function(){return y[z]}};Object.defineProperty(w,C,F)}:function(w,y,z,C){if(C===void 0)C=z;w[C]=y[z]}),f=H&&H.__setModuleDefault||(Object.create?function(w,y){Object.defineProperty(w,"default",{enumerable:!0,value:y})}:function(w,y){w.default=y}),D=H&&H.__importStar||function(w){if(w&&w.__esModule)return w;var y={};if(w!=null){for(var z in w)if(z!=="default"&&Object.prototype.hasOwnProperty.call(w,z))$(y,w,z)}return f(y,w),y},q=H&&H.__exportStar||function(w,y){for(var z in w)if(z!=="default"&&!Object.prototype.hasOwnProperty.call(y,z))$(y,w,z)};Object.defineProperty(H,"__esModule",{value:!0});H.Agent=void 0;var E=D(P("net")),Z=D(P("http")),I=P("https");q(Y(),H);var J=Symbol("AgentBaseInternalState");class U extends Z.Agent{constructor(w){super(w);this[J]={}}isSecureEndpoint(w){if(w){if(typeof w.secureEndpoint==="boolean")return w.secureEndpoint;if(typeof w.protocol==="string")return w.protocol==="https:"}let{stack:y}=Error();if(typeof y!=="string")return!1;return y.split(`
`).some((z)=>z.indexOf("(https.js:")!==-1||z.indexOf("node:https:")!==-1)}incrementSockets(w){if(this.maxSockets===1/0&&this.maxTotalSockets===1/0)return null;if(!this.sockets[w])this.sockets[w]=[];let y=new E.Socket({writable:!1});return this.sockets[w].push(y),this.totalSocketCount++,y}decrementSockets(w,y){if(!this.sockets[w]||y===null)return;let z=this.sockets[w],C=z.indexOf(y);if(C!==-1){if(z.splice(C,1),this.totalSocketCount--,z.length===0)delete this.sockets[w]}}getName(w){if(this.isSecureEndpoint(w))return I.Agent.prototype.getName.call(this,w);return super.getName(w)}createSocket(w,y,z){let C={...y,secureEndpoint:this.isSecureEndpoint(y)},F=this.getName(C),Q=this.incrementSockets(F);Promise.resolve().then(()=>this.connect(w,C)).then((K)=>{if(this.decrementSockets(F,Q),K instanceof Z.Agent)try{return K.addRequest(w,C)}catch(O){return z(O)}this[J].currentSocket=K,super.createSocket(w,y,z)},(K)=>{this.decrementSockets(F,Q),z(K)})}createConnection(){let w=this[J].currentSocket;if(this[J].currentSocket=void 0,!w)throw Error("No socket was returned in the `connect()` function");return w}get defaultPort(){return this[J].defaultPort??(this.protocol==="https:"?443:80)}set defaultPort(w){if(this[J])this[J].defaultPort=w}get protocol(){return this[J].protocol??(this.isSecureEndpoint()?"https:":"http:")}set protocol(w){if(this[J])this[J].protocol=w}}H.Agent=U});
export{T as hj};
