/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/mitm@1.7.3/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
var Net=require("net"),Tls=require("tls"),Http=require("http"),Https=require("https"),ClientRequest=Http.ClientRequest,Socket=require("./lib/socket"),TlsSocket=require("./lib/tls_socket"),EventEmitter=require("events").EventEmitter,InternalSocket=require("./lib/internal_socket"),Stubs=require("./lib/stubs"),Semver=require("semver"),slice=Function.call.bind(Array.prototype.slice),normalizeConnectArgs=Net._normalizeConnectArgs||Net._normalizeArgs,createRequestAndResponse=Http._connectionListener,NODE_0_10=Semver.satisfies(process.version,">= 0.10 < 0.11");function Mitm(){return this instanceof Mitm?(this.stubs=new Stubs,this.on("request",addCrossReferences),this):Mitm.apply(Object.create(Mitm.prototype),arguments).enable()}if(module.exports=Mitm,Mitm.prototype.on=EventEmitter.prototype.on,Mitm.prototype.once=EventEmitter.prototype.once,Mitm.prototype.off=EventEmitter.prototype.removeListener,Mitm.prototype.addListener=EventEmitter.prototype.addListener,Mitm.prototype.removeListener=EventEmitter.prototype.removeListener,Mitm.prototype.emit=EventEmitter.prototype.emit,Semver.satisfies(process.version,"^8.12 || >= 9.6")){var IncomingMessage=require("_http_incoming").IncomingMessage,ServerResponse=require("_http_server").ServerResponse,incomingMessageKey=require("_http_common").kIncomingMessage,serverResponseKey=require("_http_server").kServerResponse;Mitm.prototype[serverResponseKey]=ServerResponse,Mitm.prototype[incomingMessageKey]=IncomingMessage}function compose(){var e=arguments;return function(){for(var t=arguments,n=e.length-1;n>=0;--n)t=[e[n].apply(this,t)];return t[0]}}function defaults(e){if(null!=e)for(var t=1;t<arguments.length;++t){var n=arguments[t];for(var s in n)s in e||(e[s]=n[s])}return e}function addCrossReferences(e,t){e.res=t,t.req=e}Mitm.prototype.enable=function(){var e=this.tcpConnect.bind(this,Net.connect),t=this.tlsConnect.bind(this,Tls.connect);return this.stubs.stub(Net,"connect",e),this.stubs.stub(Net,"createConnection",e),this.stubs.stub(Http.Agent.prototype,"createConnection",e),this.stubs.stub(Tls,"connect",t),NODE_0_10&&(this.stubs.stub(Http.globalAgent,"createConnection",e),this.stubs.stub(Http.globalAgent,"maxSockets",1/0),this.stubs.stub(Https.globalAgent,"maxSockets",1/0)),Http.globalAgent.keepAlive&&this.stubs.stub(Http.globalAgent,"keepAlive",!1),Https.globalAgent.keepAlive&&this.stubs.stub(Https.globalAgent,"keepAlive",!1),this.stubs.stub(ClientRequest.prototype,"onSocket",compose(ClientRequest.prototype.onSocket,this.request.bind(this))),this},Mitm.prototype.disable=function(){return this.stubs.restore(),this},Mitm.prototype.connect=function(e,t,n,s){var r=InternalSocket.pair(),o=new t(defaults({handle:r[0],readable:!0,writable:!0},n));if(this.emit("connect",o,n),o.bypassed)return e.call(this,n,s);var i=o.serverSocket=new t({handle:r[1],readable:!0,writable:!0});return this.emit("connection",i,n),setTimeout(o.emit.bind(o,"connect")),setTimeout(i.emit.bind(i,"connect")),o},Mitm.prototype.tcpConnect=function(e,t,n){var s=normalizeConnectArgs(slice(arguments,1));t=s[0],n=s[1];var r=this.connect(e,Socket,t,n);return null==r.serverSocket||n&&r.once("connect",n),r},Mitm.prototype.tlsConnect=function(e,t,n){var s=normalizeConnectArgs(slice(arguments,1));t=s[0],n=s[1];var r=this.connect(e,TlsSocket,t,n);return null==r.serverSocket||(n&&r.once("secureConnect",n),setTimeout(r.emit.bind(r,"secureConnect"))),r},Mitm.prototype.request=function(e){if(!e.serverSocket)return e;var t=this;return NODE_0_10&&((t=Object.create(this)).emit=compose(process.nextTick,Function.bind.bind(this.emit,this))),createRequestAndResponse.call(t,e.serverSocket),e};
//# sourceMappingURL=/sm/498842f12e31594708356d1f83d9b7fd4067752b7802374cb53947b079f52477.map