diff options
author | Tekky <98614666+xtekky@users.noreply.github.com> | 2023-11-18 12:24:39 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-18 12:24:39 +0100 |
commit | 2fcb3f949bbde7f5380acc68dc6b1f938dec12bc (patch) | |
tree | 035bd400b4057a744b29a0ebee96579bfbf429f6 /g4f/Provider/npm/node_modules/undici/lib/api/api-connect.js | |
parent | ~ | g4f `v-0.1.8.5` (diff) | |
parent | Add AiChatOnline, ChatgptDemoAi, ChatgptNext Providers (diff) | |
download | gpt4free-2fcb3f949bbde7f5380acc68dc6b1f938dec12bc.tar gpt4free-2fcb3f949bbde7f5380acc68dc6b1f938dec12bc.tar.gz gpt4free-2fcb3f949bbde7f5380acc68dc6b1f938dec12bc.tar.bz2 gpt4free-2fcb3f949bbde7f5380acc68dc6b1f938dec12bc.tar.lz gpt4free-2fcb3f949bbde7f5380acc68dc6b1f938dec12bc.tar.xz gpt4free-2fcb3f949bbde7f5380acc68dc6b1f938dec12bc.tar.zst gpt4free-2fcb3f949bbde7f5380acc68dc6b1f938dec12bc.zip |
Diffstat (limited to 'g4f/Provider/npm/node_modules/undici/lib/api/api-connect.js')
-rw-r--r-- | g4f/Provider/npm/node_modules/undici/lib/api/api-connect.js | 104 |
1 files changed, 0 insertions, 104 deletions
diff --git a/g4f/Provider/npm/node_modules/undici/lib/api/api-connect.js b/g4f/Provider/npm/node_modules/undici/lib/api/api-connect.js deleted file mode 100644 index fd2b6ad9..00000000 --- a/g4f/Provider/npm/node_modules/undici/lib/api/api-connect.js +++ /dev/null @@ -1,104 +0,0 @@ -'use strict' - -const { AsyncResource } = require('async_hooks') -const { InvalidArgumentError, RequestAbortedError, SocketError } = require('../core/errors') -const util = require('../core/util') -const { addSignal, removeSignal } = require('./abort-signal') - -class ConnectHandler extends AsyncResource { - constructor (opts, callback) { - if (!opts || typeof opts !== 'object') { - throw new InvalidArgumentError('invalid opts') - } - - if (typeof callback !== 'function') { - throw new InvalidArgumentError('invalid callback') - } - - const { signal, opaque, responseHeaders } = opts - - if (signal && typeof signal.on !== 'function' && typeof signal.addEventListener !== 'function') { - throw new InvalidArgumentError('signal must be an EventEmitter or EventTarget') - } - - super('UNDICI_CONNECT') - - this.opaque = opaque || null - this.responseHeaders = responseHeaders || null - this.callback = callback - this.abort = null - - addSignal(this, signal) - } - - onConnect (abort, context) { - if (!this.callback) { - throw new RequestAbortedError() - } - - this.abort = abort - this.context = context - } - - onHeaders () { - throw new SocketError('bad connect', null) - } - - onUpgrade (statusCode, rawHeaders, socket) { - const { callback, opaque, context } = this - - removeSignal(this) - - this.callback = null - - let headers = rawHeaders - // Indicates is an HTTP2Session - if (headers != null) { - headers = this.responseHeaders === 'raw' ? util.parseRawHeaders(rawHeaders) : util.parseHeaders(rawHeaders) - } - - this.runInAsyncScope(callback, null, null, { - statusCode, - headers, - socket, - opaque, - context - }) - } - - onError (err) { - const { callback, opaque } = this - - removeSignal(this) - - if (callback) { - this.callback = null - queueMicrotask(() => { - this.runInAsyncScope(callback, null, err, { opaque }) - }) - } - } -} - -function connect (opts, callback) { - if (callback === undefined) { - return new Promise((resolve, reject) => { - connect.call(this, opts, (err, data) => { - return err ? reject(err) : resolve(data) - }) - }) - } - - try { - const connectHandler = new ConnectHandler(opts, callback) - this.dispatch({ ...opts, method: 'CONNECT' }, connectHandler) - } catch (err) { - if (typeof callback !== 'function') { - throw err - } - const opaque = opts && opts.opaque - queueMicrotask(() => callback(err, { opaque })) - } -} - -module.exports = connect |