diff options
| author | Joel Kronqvist <joel.h.kronqvist@gmail.com> | 2022-03-05 19:02:27 +0200 | 
|---|---|---|
| committer | Joel Kronqvist <joel.h.kronqvist@gmail.com> | 2022-03-05 19:02:27 +0200 | 
| commit | 5d309ff52cd399a6b71968a6b9a70c8ac0b98981 (patch) | |
| tree | 360f7eb50f956e2367ef38fa1fc6ac7ac5258042 /node_modules/agent-base | |
| parent | b500a50f1b97d93c98b36ed9a980f8188d648147 (diff) | |
| download | LYLLRuoka-5d309ff52cd399a6b71968a6b9a70c8ac0b98981.tar.gz LYLLRuoka-5d309ff52cd399a6b71968a6b9a70c8ac0b98981.zip  | |
Added node_modules for the updating to work properly.
Diffstat (limited to 'node_modules/agent-base')
| -rw-r--r-- | node_modules/agent-base/README.md | 145 | ||||
| -rw-r--r-- | node_modules/agent-base/dist/src/index.d.ts | 78 | ||||
| -rw-r--r-- | node_modules/agent-base/dist/src/index.js | 203 | ||||
| -rw-r--r-- | node_modules/agent-base/dist/src/index.js.map | 1 | ||||
| -rw-r--r-- | node_modules/agent-base/dist/src/promisify.d.ts | 4 | ||||
| -rw-r--r-- | node_modules/agent-base/dist/src/promisify.js | 18 | ||||
| -rw-r--r-- | node_modules/agent-base/dist/src/promisify.js.map | 1 | ||||
| -rw-r--r-- | node_modules/agent-base/package.json | 64 | ||||
| -rw-r--r-- | node_modules/agent-base/src/index.ts | 345 | ||||
| -rw-r--r-- | node_modules/agent-base/src/promisify.ts | 33 | 
10 files changed, 892 insertions, 0 deletions
diff --git a/node_modules/agent-base/README.md b/node_modules/agent-base/README.md new file mode 100644 index 0000000..256f1f3 --- /dev/null +++ b/node_modules/agent-base/README.md @@ -0,0 +1,145 @@ +agent-base +========== +### Turn a function into an [`http.Agent`][http.Agent] instance +[](https://github.com/TooTallNate/node-agent-base/actions?workflow=Node+CI) + +This module provides an `http.Agent` generator. That is, you pass it an async +callback function, and it returns a new `http.Agent` instance that will invoke the +given callback function when sending outbound HTTP requests. + +#### Some subclasses: + +Here's some more interesting uses of `agent-base`. +Send a pull request to list yours! + + * [`http-proxy-agent`][http-proxy-agent]: An HTTP(s) proxy `http.Agent` implementation for HTTP endpoints + * [`https-proxy-agent`][https-proxy-agent]: An HTTP(s) proxy `http.Agent` implementation for HTTPS endpoints + * [`pac-proxy-agent`][pac-proxy-agent]: A PAC file proxy `http.Agent` implementation for HTTP and HTTPS + * [`socks-proxy-agent`][socks-proxy-agent]: A SOCKS proxy `http.Agent` implementation for HTTP and HTTPS + + +Installation +------------ + +Install with `npm`: + +``` bash +$ npm install agent-base +``` + + +Example +------- + +Here's a minimal example that creates a new `net.Socket` connection to the server +for every HTTP request (i.e. the equivalent of `agent: false` option): + +```js +var net = require('net'); +var tls = require('tls'); +var url = require('url'); +var http = require('http'); +var agent = require('agent-base'); + +var endpoint = 'http://nodejs.org/api/'; +var parsed = url.parse(endpoint); + +// This is the important part! +parsed.agent = agent(function (req, opts) { +  var socket; +  // `secureEndpoint` is true when using the https module +  if (opts.secureEndpoint) { +    socket = tls.connect(opts); +  } else { +    socket = net.connect(opts); +  } +  return socket; +}); + +// Everything else works just like normal... +http.get(parsed, function (res) { +  console.log('"response" event!', res.headers); +  res.pipe(process.stdout); +}); +``` + +Returning a Promise or using an `async` function is also supported: + +```js +agent(async function (req, opts) { +  await sleep(1000); +  // etc… +}); +``` + +Return another `http.Agent` instance to "pass through" the responsibility +for that HTTP request to that agent: + +```js +agent(function (req, opts) { +  return opts.secureEndpoint ? https.globalAgent : http.globalAgent; +}); +``` + + +API +--- + +## Agent(Function callback[, Object options]) → [http.Agent][] + +Creates a base `http.Agent` that will execute the callback function `callback` +for every HTTP request that it is used as the `agent` for. The callback function +is responsible for creating a `stream.Duplex` instance of some kind that will be +used as the underlying socket in the HTTP request. + +The `options` object accepts the following properties: + +  * `timeout` - Number - Timeout for the `callback()` function in milliseconds. Defaults to Infinity (optional). + +The callback function should have the following signature: + +### callback(http.ClientRequest req, Object options, Function cb) → undefined + +The ClientRequest `req` can be accessed to read request headers and +and the path, etc. The `options` object contains the options passed +to the `http.request()`/`https.request()` function call, and is formatted +to be directly passed to `net.connect()`/`tls.connect()`, or however +else you want a Socket to be created. Pass the created socket to +the callback function `cb` once created, and the HTTP request will +continue to proceed. + +If the `https` module is used to invoke the HTTP request, then the +`secureEndpoint` property on `options` _will be set to `true`_. + + +License +------- + +(The MIT License) + +Copyright (c) 2013 Nathan Rajlich <nathan@tootallnate.net> + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +[http-proxy-agent]: https://github.com/TooTallNate/node-http-proxy-agent +[https-proxy-agent]: https://github.com/TooTallNate/node-https-proxy-agent +[pac-proxy-agent]: https://github.com/TooTallNate/node-pac-proxy-agent +[socks-proxy-agent]: https://github.com/TooTallNate/node-socks-proxy-agent +[http.Agent]: https://nodejs.org/api/http.html#http_class_http_agent diff --git a/node_modules/agent-base/dist/src/index.d.ts b/node_modules/agent-base/dist/src/index.d.ts new file mode 100644 index 0000000..bc4ab74 --- /dev/null +++ b/node_modules/agent-base/dist/src/index.d.ts @@ -0,0 +1,78 @@ +/// <reference types="node" /> +import net from 'net'; +import http from 'http'; +import https from 'https'; +import { Duplex } from 'stream'; +import { EventEmitter } from 'events'; +declare function createAgent(opts?: createAgent.AgentOptions): createAgent.Agent; +declare function createAgent(callback: createAgent.AgentCallback, opts?: createAgent.AgentOptions): createAgent.Agent; +declare namespace createAgent { +    interface ClientRequest extends http.ClientRequest { +        _last?: boolean; +        _hadError?: boolean; +        method: string; +    } +    interface AgentRequestOptions { +        host?: string; +        path?: string; +        port: number; +    } +    interface HttpRequestOptions extends AgentRequestOptions, Omit<http.RequestOptions, keyof AgentRequestOptions> { +        secureEndpoint: false; +    } +    interface HttpsRequestOptions extends AgentRequestOptions, Omit<https.RequestOptions, keyof AgentRequestOptions> { +        secureEndpoint: true; +    } +    type RequestOptions = HttpRequestOptions | HttpsRequestOptions; +    type AgentLike = Pick<createAgent.Agent, 'addRequest'> | http.Agent; +    type AgentCallbackReturn = Duplex | AgentLike; +    type AgentCallbackCallback = (err?: Error | null, socket?: createAgent.AgentCallbackReturn) => void; +    type AgentCallbackPromise = (req: createAgent.ClientRequest, opts: createAgent.RequestOptions) => createAgent.AgentCallbackReturn | Promise<createAgent.AgentCallbackReturn>; +    type AgentCallback = typeof Agent.prototype.callback; +    type AgentOptions = { +        timeout?: number; +    }; +    /** +     * Base `http.Agent` implementation. +     * No pooling/keep-alive is implemented by default. +     * +     * @param {Function} callback +     * @api public +     */ +    class Agent extends EventEmitter { +        timeout: number | null; +        maxFreeSockets: number; +        maxTotalSockets: number; +        maxSockets: number; +        sockets: { +            [key: string]: net.Socket[]; +        }; +        freeSockets: { +            [key: string]: net.Socket[]; +        }; +        requests: { +            [key: string]: http.IncomingMessage[]; +        }; +        options: https.AgentOptions; +        private promisifiedCallback?; +        private explicitDefaultPort?; +        private explicitProtocol?; +        constructor(callback?: createAgent.AgentCallback | createAgent.AgentOptions, _opts?: createAgent.AgentOptions); +        get defaultPort(): number; +        set defaultPort(v: number); +        get protocol(): string; +        set protocol(v: string); +        callback(req: createAgent.ClientRequest, opts: createAgent.RequestOptions, fn: createAgent.AgentCallbackCallback): void; +        callback(req: createAgent.ClientRequest, opts: createAgent.RequestOptions): createAgent.AgentCallbackReturn | Promise<createAgent.AgentCallbackReturn>; +        /** +         * Called by node-core's "_http_client.js" module when creating +         * a new HTTP request with this Agent instance. +         * +         * @api public +         */ +        addRequest(req: ClientRequest, _opts: RequestOptions): void; +        freeSocket(socket: net.Socket, opts: AgentOptions): void; +        destroy(): void; +    } +} +export = createAgent; diff --git a/node_modules/agent-base/dist/src/index.js b/node_modules/agent-base/dist/src/index.js new file mode 100644 index 0000000..bfd9e22 --- /dev/null +++ b/node_modules/agent-base/dist/src/index.js @@ -0,0 +1,203 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { +    return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +const events_1 = require("events"); +const debug_1 = __importDefault(require("debug")); +const promisify_1 = __importDefault(require("./promisify")); +const debug = debug_1.default('agent-base'); +function isAgent(v) { +    return Boolean(v) && typeof v.addRequest === 'function'; +} +function isSecureEndpoint() { +    const { stack } = new Error(); +    if (typeof stack !== 'string') +        return false; +    return stack.split('\n').some(l => l.indexOf('(https.js:') !== -1 || l.indexOf('node:https:') !== -1); +} +function createAgent(callback, opts) { +    return new createAgent.Agent(callback, opts); +} +(function (createAgent) { +    /** +     * Base `http.Agent` implementation. +     * No pooling/keep-alive is implemented by default. +     * +     * @param {Function} callback +     * @api public +     */ +    class Agent extends events_1.EventEmitter { +        constructor(callback, _opts) { +            super(); +            let opts = _opts; +            if (typeof callback === 'function') { +                this.callback = callback; +            } +            else if (callback) { +                opts = callback; +            } +            // Timeout for the socket to be returned from the callback +            this.timeout = null; +            if (opts && typeof opts.timeout === 'number') { +                this.timeout = opts.timeout; +            } +            // These aren't actually used by `agent-base`, but are required +            // for the TypeScript definition files in `@types/node` :/ +            this.maxFreeSockets = 1; +            this.maxSockets = 1; +            this.maxTotalSockets = Infinity; +            this.sockets = {}; +            this.freeSockets = {}; +            this.requests = {}; +            this.options = {}; +        } +        get defaultPort() { +            if (typeof this.explicitDefaultPort === 'number') { +                return this.explicitDefaultPort; +            } +            return isSecureEndpoint() ? 443 : 80; +        } +        set defaultPort(v) { +            this.explicitDefaultPort = v; +        } +        get protocol() { +            if (typeof this.explicitProtocol === 'string') { +                return this.explicitProtocol; +            } +            return isSecureEndpoint() ? 'https:' : 'http:'; +        } +        set protocol(v) { +            this.explicitProtocol = v; +        } +        callback(req, opts, fn) { +            throw new Error('"agent-base" has no default implementation, you must subclass and override `callback()`'); +        } +        /** +         * Called by node-core's "_http_client.js" module when creating +         * a new HTTP request with this Agent instance. +         * +         * @api public +         */ +        addRequest(req, _opts) { +            const opts = Object.assign({}, _opts); +            if (typeof opts.secureEndpoint !== 'boolean') { +                opts.secureEndpoint = isSecureEndpoint(); +            } +            if (opts.host == null) { +                opts.host = 'localhost'; +            } +            if (opts.port == null) { +                opts.port = opts.secureEndpoint ? 443 : 80; +            } +            if (opts.protocol == null) { +                opts.protocol = opts.secureEndpoint ? 'https:' : 'http:'; +            } +            if (opts.host && opts.path) { +                // If both a `host` and `path` are specified then it's most +                // likely the result of a `url.parse()` call... we need to +                // remove the `path` portion so that `net.connect()` doesn't +                // attempt to open that as a unix socket file. +                delete opts.path; +            } +            delete opts.agent; +            delete opts.hostname; +            delete opts._defaultAgent; +            delete opts.defaultPort; +            delete opts.createConnection; +            // Hint to use "Connection: close" +            // XXX: non-documented `http` module API :( +            req._last = true; +            req.shouldKeepAlive = false; +            let timedOut = false; +            let timeoutId = null; +            const timeoutMs = opts.timeout || this.timeout; +            const onerror = (err) => { +                if (req._hadError) +                    return; +                req.emit('error', err); +                // For Safety. Some additional errors might fire later on +                // and we need to make sure we don't double-fire the error event. +                req._hadError = true; +            }; +            const ontimeout = () => { +                timeoutId = null; +                timedOut = true; +                const err = new Error(`A "socket" was not created for HTTP request before ${timeoutMs}ms`); +                err.code = 'ETIMEOUT'; +                onerror(err); +            }; +            const callbackError = (err) => { +                if (timedOut) +                    return; +                if (timeoutId !== null) { +                    clearTimeout(timeoutId); +                    timeoutId = null; +                } +                onerror(err); +            }; +            const onsocket = (socket) => { +                if (timedOut) +                    return; +                if (timeoutId != null) { +                    clearTimeout(timeoutId); +                    timeoutId = null; +                } +                if (isAgent(socket)) { +                    // `socket` is actually an `http.Agent` instance, so +                    // relinquish responsibility for this `req` to the Agent +                    // from here on +                    debug('Callback returned another Agent instance %o', socket.constructor.name); +                    socket.addRequest(req, opts); +                    return; +                } +                if (socket) { +                    socket.once('free', () => { +                        this.freeSocket(socket, opts); +                    }); +                    req.onSocket(socket); +                    return; +                } +                const err = new Error(`no Duplex stream was returned to agent-base for \`${req.method} ${req.path}\``); +                onerror(err); +            }; +            if (typeof this.callback !== 'function') { +                onerror(new Error('`callback` is not defined')); +                return; +            } +            if (!this.promisifiedCallback) { +                if (this.callback.length >= 3) { +                    debug('Converting legacy callback function to promise'); +                    this.promisifiedCallback = promisify_1.default(this.callback); +                } +                else { +                    this.promisifiedCallback = this.callback; +                } +            } +            if (typeof timeoutMs === 'number' && timeoutMs > 0) { +                timeoutId = setTimeout(ontimeout, timeoutMs); +            } +            if ('port' in opts && typeof opts.port !== 'number') { +                opts.port = Number(opts.port); +            } +            try { +                debug('Resolving socket for %o request: %o', opts.protocol, `${req.method} ${req.path}`); +                Promise.resolve(this.promisifiedCallback(req, opts)).then(onsocket, callbackError); +            } +            catch (err) { +                Promise.reject(err).catch(callbackError); +            } +        } +        freeSocket(socket, opts) { +            debug('Freeing socket %o %o', socket.constructor.name, opts); +            socket.destroy(); +        } +        destroy() { +            debug('Destroying agent %o', this.constructor.name); +        } +    } +    createAgent.Agent = Agent; +    // So that `instanceof` works correctly +    createAgent.prototype = createAgent.Agent.prototype; +})(createAgent || (createAgent = {})); +module.exports = createAgent; +//# sourceMappingURL=index.js.map
\ No newline at end of file diff --git a/node_modules/agent-base/dist/src/index.js.map b/node_modules/agent-base/dist/src/index.js.map new file mode 100644 index 0000000..bd118ab --- /dev/null +++ b/node_modules/agent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,IAAI,CAAC,mBAAmB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CACxD,QAAQ,EACR,aAAa,CACb,CAAC;aACF;YAAC,OAAO,GAAG,EAAE;gBACb,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;aACzC;QACF,CAAC;QAED,UAAU,CAAC,MAAkB,EAAE,IAAkB;YAChD,KAAK,CAAC,sBAAsB,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC7D,MAAM,CAAC,OAAO,EAAE,CAAC;QAClB,CAAC;QAED,OAAO;YACN,KAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACrD,CAAC;KACD;IAxPY,iBAAK,QAwPjB,CAAA;IAED,uCAAuC;IACvC,WAAW,CAAC,SAAS,GAAG,WAAW,CAAC,KAAK,CAAC,SAAS,CAAC;AACrD,CAAC,EAtTS,WAAW,KAAX,WAAW,QAsTpB;AAED,iBAAS,WAAW,CAAC"}
\ No newline at end of file diff --git a/node_modules/agent-base/dist/src/promisify.d.ts b/node_modules/agent-base/dist/src/promisify.d.ts new file mode 100644 index 0000000..0268869 --- /dev/null +++ b/node_modules/agent-base/dist/src/promisify.d.ts @@ -0,0 +1,4 @@ +import { ClientRequest, RequestOptions, AgentCallbackCallback, AgentCallbackPromise } from './index'; +declare type LegacyCallback = (req: ClientRequest, opts: RequestOptions, fn: AgentCallbackCallback) => void; +export default function promisify(fn: LegacyCallback): AgentCallbackPromise; +export {}; diff --git a/node_modules/agent-base/dist/src/promisify.js b/node_modules/agent-base/dist/src/promisify.js new file mode 100644 index 0000000..b2f6132 --- /dev/null +++ b/node_modules/agent-base/dist/src/promisify.js @@ -0,0 +1,18 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +function promisify(fn) { +    return function (req, opts) { +        return new Promise((resolve, reject) => { +            fn.call(this, req, opts, (err, rtn) => { +                if (err) { +                    reject(err); +                } +                else { +                    resolve(rtn); +                } +            }); +        }); +    }; +} +exports.default = promisify; +//# sourceMappingURL=promisify.js.map
\ No newline at end of file diff --git a/node_modules/agent-base/dist/src/promisify.js.map b/node_modules/agent-base/dist/src/promisify.js.map new file mode 100644 index 0000000..4bff9bf --- /dev/null +++ b/node_modules/agent-base/dist/src/promisify.js.map @@ -0,0 +1 @@ +{"version":3,"file":"promisify.js","sourceRoot":"","sources":["../../src/promisify.ts"],"names":[],"mappings":";;AAeA,SAAwB,SAAS,CAAC,EAAkB;IACnD,OAAO,UAAsB,GAAkB,EAAE,IAAoB;QACpE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACtC,EAAE,CAAC,IAAI,CACN,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,CAAC,GAA6B,EAAE,GAAyB,EAAE,EAAE;gBAC5D,IAAI,GAAG,EAAE;oBACR,MAAM,CAAC,GAAG,CAAC,CAAC;iBACZ;qBAAM;oBACN,OAAO,CAAC,GAAG,CAAC,CAAC;iBACb;YACF,CAAC,CACD,CAAC;QACH,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC;AACH,CAAC;AAjBD,4BAiBC"}
\ No newline at end of file diff --git a/node_modules/agent-base/package.json b/node_modules/agent-base/package.json new file mode 100644 index 0000000..fadce3a --- /dev/null +++ b/node_modules/agent-base/package.json @@ -0,0 +1,64 @@ +{ +  "name": "agent-base", +  "version": "6.0.2", +  "description": "Turn a function into an `http.Agent` instance", +  "main": "dist/src/index", +  "typings": "dist/src/index", +  "files": [ +    "dist/src", +    "src" +  ], +  "scripts": { +    "prebuild": "rimraf dist", +    "build": "tsc", +    "postbuild": "cpy --parents src test '!**/*.ts' dist", +    "test": "mocha --reporter spec dist/test/*.js", +    "test-lint": "eslint src --ext .js,.ts", +    "prepublishOnly": "npm run build" +  }, +  "repository": { +    "type": "git", +    "url": "git://github.com/TooTallNate/node-agent-base.git" +  }, +  "keywords": [ +    "http", +    "agent", +    "base", +    "barebones", +    "https" +  ], +  "author": "Nathan Rajlich <nathan@tootallnate.net> (http://n8.io/)", +  "license": "MIT", +  "bugs": { +    "url": "https://github.com/TooTallNate/node-agent-base/issues" +  }, +  "dependencies": { +    "debug": "4" +  }, +  "devDependencies": { +    "@types/debug": "4", +    "@types/mocha": "^5.2.7", +    "@types/node": "^14.0.20", +    "@types/semver": "^7.1.0", +    "@types/ws": "^6.0.3", +    "@typescript-eslint/eslint-plugin": "1.6.0", +    "@typescript-eslint/parser": "1.1.0", +    "async-listen": "^1.2.0", +    "cpy-cli": "^2.0.0", +    "eslint": "5.16.0", +    "eslint-config-airbnb": "17.1.0", +    "eslint-config-prettier": "4.1.0", +    "eslint-import-resolver-typescript": "1.1.1", +    "eslint-plugin-import": "2.16.0", +    "eslint-plugin-jsx-a11y": "6.2.1", +    "eslint-plugin-react": "7.12.4", +    "mocha": "^6.2.0", +    "rimraf": "^3.0.0", +    "semver": "^7.1.2", +    "typescript": "^3.5.3", +    "ws": "^3.0.0" +  }, +  "engines": { +    "node": ">= 6.0.0" +  } +} diff --git a/node_modules/agent-base/src/index.ts b/node_modules/agent-base/src/index.ts new file mode 100644 index 0000000..a47ccd4 --- /dev/null +++ b/node_modules/agent-base/src/index.ts @@ -0,0 +1,345 @@ +import net from 'net'; +import http from 'http'; +import https from 'https'; +import { Duplex } from 'stream'; +import { EventEmitter } from 'events'; +import createDebug from 'debug'; +import promisify from './promisify'; + +const debug = createDebug('agent-base'); + +function isAgent(v: any): v is createAgent.AgentLike { +	return Boolean(v) && typeof v.addRequest === 'function'; +} + +function isSecureEndpoint(): boolean { +	const { stack } = new Error(); +	if (typeof stack !== 'string') return false; +	return stack.split('\n').some(l => l.indexOf('(https.js:') !== -1  || l.indexOf('node:https:') !== -1); +} + +function createAgent(opts?: createAgent.AgentOptions): createAgent.Agent; +function createAgent( +	callback: createAgent.AgentCallback, +	opts?: createAgent.AgentOptions +): createAgent.Agent; +function createAgent( +	callback?: createAgent.AgentCallback | createAgent.AgentOptions, +	opts?: createAgent.AgentOptions +) { +	return new createAgent.Agent(callback, opts); +} + +namespace createAgent { +	export interface ClientRequest extends http.ClientRequest { +		_last?: boolean; +		_hadError?: boolean; +		method: string; +	} + +	export interface AgentRequestOptions { +		host?: string; +		path?: string; +		// `port` on `http.RequestOptions` can be a string or undefined, +		// but `net.TcpNetConnectOpts` expects only a number +		port: number; +	} + +	export interface HttpRequestOptions +		extends AgentRequestOptions, +			Omit<http.RequestOptions, keyof AgentRequestOptions> { +		secureEndpoint: false; +	} + +	export interface HttpsRequestOptions +		extends AgentRequestOptions, +			Omit<https.RequestOptions, keyof AgentRequestOptions> { +		secureEndpoint: true; +	} + +	export type RequestOptions = HttpRequestOptions | HttpsRequestOptions; + +	export type AgentLike = Pick<createAgent.Agent, 'addRequest'> | http.Agent; + +	export type AgentCallbackReturn = Duplex | AgentLike; + +	export type AgentCallbackCallback = ( +		err?: Error | null, +		socket?: createAgent.AgentCallbackReturn +	) => void; + +	export type AgentCallbackPromise = ( +		req: createAgent.ClientRequest, +		opts: createAgent.RequestOptions +	) => +		| createAgent.AgentCallbackReturn +		| Promise<createAgent.AgentCallbackReturn>; + +	export type AgentCallback = typeof Agent.prototype.callback; + +	export type AgentOptions = { +		timeout?: number; +	}; + +	/** +	 * Base `http.Agent` implementation. +	 * No pooling/keep-alive is implemented by default. +	 * +	 * @param {Function} callback +	 * @api public +	 */ +	export class Agent extends EventEmitter { +		public timeout: number | null; +		public maxFreeSockets: number; +		public maxTotalSockets: number; +		public maxSockets: number; +		public sockets: { +			[key: string]: net.Socket[]; +		}; +		public freeSockets: { +			[key: string]: net.Socket[]; +		}; +		public requests: { +			[key: string]: http.IncomingMessage[]; +		}; +		public options: https.AgentOptions; +		private promisifiedCallback?: createAgent.AgentCallbackPromise; +		private explicitDefaultPort?: number; +		private explicitProtocol?: string; + +		constructor( +			callback?: createAgent.AgentCallback | createAgent.AgentOptions, +			_opts?: createAgent.AgentOptions +		) { +			super(); + +			let opts = _opts; +			if (typeof callback === 'function') { +				this.callback = callback; +			} else if (callback) { +				opts = callback; +			} + +			// Timeout for the socket to be returned from the callback +			this.timeout = null; +			if (opts && typeof opts.timeout === 'number') { +				this.timeout = opts.timeout; +			} + +			// These aren't actually used by `agent-base`, but are required +			// for the TypeScript definition files in `@types/node` :/ +			this.maxFreeSockets = 1; +			this.maxSockets = 1; +			this.maxTotalSockets = Infinity; +			this.sockets = {}; +			this.freeSockets = {}; +			this.requests = {}; +			this.options = {}; +		} + +		get defaultPort(): number { +			if (typeof this.explicitDefaultPort === 'number') { +				return this.explicitDefaultPort; +			} +			return isSecureEndpoint() ? 443 : 80; +		} + +		set defaultPort(v: number) { +			this.explicitDefaultPort = v; +		} + +		get protocol(): string { +			if (typeof this.explicitProtocol === 'string') { +				return this.explicitProtocol; +			} +			return isSecureEndpoint() ? 'https:' : 'http:'; +		} + +		set protocol(v: string) { +			this.explicitProtocol = v; +		} + +		callback( +			req: createAgent.ClientRequest, +			opts: createAgent.RequestOptions, +			fn: createAgent.AgentCallbackCallback +		): void; +		callback( +			req: createAgent.ClientRequest, +			opts: createAgent.RequestOptions +		): +			| createAgent.AgentCallbackReturn +			| Promise<createAgent.AgentCallbackReturn>; +		callback( +			req: createAgent.ClientRequest, +			opts: createAgent.AgentOptions, +			fn?: createAgent.AgentCallbackCallback +		): +			| createAgent.AgentCallbackReturn +			| Promise<createAgent.AgentCallbackReturn> +			| void { +			throw new Error( +				'"agent-base" has no default implementation, you must subclass and override `callback()`' +			); +		} + +		/** +		 * Called by node-core's "_http_client.js" module when creating +		 * a new HTTP request with this Agent instance. +		 * +		 * @api public +		 */ +		addRequest(req: ClientRequest, _opts: RequestOptions): void { +			const opts: RequestOptions = { ..._opts }; + +			if (typeof opts.secureEndpoint !== 'boolean') { +				opts.secureEndpoint = isSecureEndpoint(); +			} + +			if (opts.host == null) { +				opts.host = 'localhost'; +			} + +			if (opts.port == null) { +				opts.port = opts.secureEndpoint ? 443 : 80; +			} + +			if (opts.protocol == null) { +				opts.protocol = opts.secureEndpoint ? 'https:' : 'http:'; +			} + +			if (opts.host && opts.path) { +				// If both a `host` and `path` are specified then it's most +				// likely the result of a `url.parse()` call... we need to +				// remove the `path` portion so that `net.connect()` doesn't +				// attempt to open that as a unix socket file. +				delete opts.path; +			} + +			delete opts.agent; +			delete opts.hostname; +			delete opts._defaultAgent; +			delete opts.defaultPort; +			delete opts.createConnection; + +			// Hint to use "Connection: close" +			// XXX: non-documented `http` module API :( +			req._last = true; +			req.shouldKeepAlive = false; + +			let timedOut = false; +			let timeoutId: ReturnType<typeof setTimeout> | null = null; +			const timeoutMs = opts.timeout || this.timeout; + +			const onerror = (err: NodeJS.ErrnoException) => { +				if (req._hadError) return; +				req.emit('error', err); +				// For Safety. Some additional errors might fire later on +				// and we need to make sure we don't double-fire the error event. +				req._hadError = true; +			}; + +			const ontimeout = () => { +				timeoutId = null; +				timedOut = true; +				const err: NodeJS.ErrnoException = new Error( +					`A "socket" was not created for HTTP request before ${timeoutMs}ms` +				); +				err.code = 'ETIMEOUT'; +				onerror(err); +			}; + +			const callbackError = (err: NodeJS.ErrnoException) => { +				if (timedOut) return; +				if (timeoutId !== null) { +					clearTimeout(timeoutId); +					timeoutId = null; +				} +				onerror(err); +			}; + +			const onsocket = (socket: AgentCallbackReturn) => { +				if (timedOut) return; +				if (timeoutId != null) { +					clearTimeout(timeoutId); +					timeoutId = null; +				} + +				if (isAgent(socket)) { +					// `socket` is actually an `http.Agent` instance, so +					// relinquish responsibility for this `req` to the Agent +					// from here on +					debug( +						'Callback returned another Agent instance %o', +						socket.constructor.name +					); +					(socket as createAgent.Agent).addRequest(req, opts); +					return; +				} + +				if (socket) { +					socket.once('free', () => { +						this.freeSocket(socket as net.Socket, opts); +					}); +					req.onSocket(socket as net.Socket); +					return; +				} + +				const err = new Error( +					`no Duplex stream was returned to agent-base for \`${req.method} ${req.path}\`` +				); +				onerror(err); +			}; + +			if (typeof this.callback !== 'function') { +				onerror(new Error('`callback` is not defined')); +				return; +			} + +			if (!this.promisifiedCallback) { +				if (this.callback.length >= 3) { +					debug('Converting legacy callback function to promise'); +					this.promisifiedCallback = promisify(this.callback); +				} else { +					this.promisifiedCallback = this.callback; +				} +			} + +			if (typeof timeoutMs === 'number' && timeoutMs > 0) { +				timeoutId = setTimeout(ontimeout, timeoutMs); +			} + +			if ('port' in opts && typeof opts.port !== 'number') { +				opts.port = Number(opts.port); +			} + +			try { +				debug( +					'Resolving socket for %o request: %o', +					opts.protocol, +					`${req.method} ${req.path}` +				); +				Promise.resolve(this.promisifiedCallback(req, opts)).then( +					onsocket, +					callbackError +				); +			} catch (err) { +				Promise.reject(err).catch(callbackError); +			} +		} + +		freeSocket(socket: net.Socket, opts: AgentOptions) { +			debug('Freeing socket %o %o', socket.constructor.name, opts); +			socket.destroy(); +		} + +		destroy() { +			debug('Destroying agent %o', this.constructor.name); +		} +	} + +	// So that `instanceof` works correctly +	createAgent.prototype = createAgent.Agent.prototype; +} + +export = createAgent; diff --git a/node_modules/agent-base/src/promisify.ts b/node_modules/agent-base/src/promisify.ts new file mode 100644 index 0000000..60cc662 --- /dev/null +++ b/node_modules/agent-base/src/promisify.ts @@ -0,0 +1,33 @@ +import { +	Agent, +	ClientRequest, +	RequestOptions, +	AgentCallbackCallback, +	AgentCallbackPromise, +	AgentCallbackReturn +} from './index'; + +type LegacyCallback = ( +	req: ClientRequest, +	opts: RequestOptions, +	fn: AgentCallbackCallback +) => void; + +export default function promisify(fn: LegacyCallback): AgentCallbackPromise { +	return function(this: Agent, req: ClientRequest, opts: RequestOptions) { +		return new Promise((resolve, reject) => { +			fn.call( +				this, +				req, +				opts, +				(err: Error | null | undefined, rtn?: AgentCallbackReturn) => { +					if (err) { +						reject(err); +					} else { +						resolve(rtn); +					} +				} +			); +		}); +	}; +}  | 
