File
Blob: src/node/internal/internal_https_agent.ts
| 1 | // Copyright (c) 2017-2022 Cloudflare, Inc. |
| 2 | // Licensed under the Apache 2.0 license found in the LICENSE file or at: |
| 3 | // https://opensource.org/licenses/Apache-2.0 |
| 4 | // Copyright Joyent and Node contributors. All rights reserved. MIT license. |
| 5 | |
| 6 | /* eslint-disable @typescript-eslint/no-deprecated,@typescript-eslint/restrict-plus-operands */ |
| 7 | |
| 8 | import { Agent as HttpAgent } from 'node-internal:internal_http_agent'; |
| 9 | import type { AgentOptions } from 'node:http'; |
| 10 | import type { RequestOptions } from 'node:https'; |
| 11 | |
| 12 | export class Agent extends HttpAgent { |
| 13 | maxCachedSessions: number = 100; |
| 14 | |
| 15 | constructor(options?: AgentOptions) { |
| 16 | // Match Node.js: the HTTPS Agent constructor sets defaultPort and protocol |
| 17 | // on the options object before passing them to the base HTTP Agent constructor, |
| 18 | // so they end up on both this.options and this.defaultPort/this.protocol. |
| 19 | /* eslint-disable @typescript-eslint/no-unsafe-assignment, |
| 20 | @typescript-eslint/no-unsafe-member-access, |
| 21 | @typescript-eslint/no-unsafe-argument, |
| 22 | @typescript-eslint/no-explicit-any */ |
| 23 | const opts = { ...options } as any; |
| 24 | opts.defaultPort ??= 443; |
| 25 | opts.protocol ??= 'https:'; |
| 26 | super(opts); |
| 27 | /* eslint-enable @typescript-eslint/no-unsafe-assignment, |
| 28 | @typescript-eslint/no-unsafe-member-access, |
| 29 | @typescript-eslint/no-unsafe-argument, |
| 30 | @typescript-eslint/no-explicit-any */ |
| 31 | } |
| 32 | |
| 33 | override getName(options: RequestOptions = {}): string { |
| 34 | let name = super.getName(options); |
| 35 | |
| 36 | name += ':'; |
| 37 | if (options.ca) name += options.ca; |
| 38 | |
| 39 | name += ':'; |
| 40 | if (options.cert) name += options.cert; |
| 41 | |
| 42 | name += ':'; |
| 43 | if (options.clientCertEngine) name += options.clientCertEngine; |
| 44 | |
| 45 | name += ':'; |
| 46 | if (options.ciphers) name += options.ciphers; |
| 47 | |
| 48 | name += ':'; |
| 49 | // eslint-disable-next-line @typescript-eslint/no-base-to-string |
| 50 | if (options.key) name += options.key; |
| 51 | |
| 52 | name += ':'; |
| 53 | // eslint-disable-next-line @typescript-eslint/no-base-to-string |
| 54 | if (options.pfx) name += options.pfx; |
| 55 | |
| 56 | name += ':'; |
| 57 | if (options.rejectUnauthorized !== undefined) |
| 58 | name += options.rejectUnauthorized; |
| 59 | |
| 60 | name += ':'; |
| 61 | if (options.servername && options.servername !== options.host) |
| 62 | name += options.servername; |
| 63 | |
| 64 | name += ':'; |
| 65 | if (options.minVersion) name += options.minVersion; |
| 66 | |
| 67 | name += ':'; |
| 68 | if (options.maxVersion) name += options.maxVersion; |
| 69 | |
| 70 | name += ':'; |
| 71 | if (options.secureProtocol) name += options.secureProtocol; |
| 72 | |
| 73 | name += ':'; |
| 74 | if (options.crl) name += options.crl; |
| 75 | |
| 76 | name += ':'; |
| 77 | if (options.honorCipherOrder !== undefined) |
| 78 | name += options.honorCipherOrder; |
| 79 | |
| 80 | name += ':'; |
| 81 | if (options.ecdhCurve) name += options.ecdhCurve; |
| 82 | |
| 83 | name += ':'; |
| 84 | if (options.dhparam) name += options.dhparam; |
| 85 | |
| 86 | name += ':'; |
| 87 | if (options.secureOptions !== undefined) name += options.secureOptions; |
| 88 | |
| 89 | name += ':'; |
| 90 | if (options.sessionIdContext) name += options.sessionIdContext; |
| 91 | |
| 92 | name += ':'; |
| 93 | if (options.sigalgs) name += JSON.stringify(options.sigalgs); |
| 94 | |
| 95 | name += ':'; |
| 96 | if (options.privateKeyIdentifier) name += options.privateKeyIdentifier; |
| 97 | |
| 98 | name += ':'; |
| 99 | if (options.privateKeyEngine) name += options.privateKeyEngine; |
| 100 | |
| 101 | return name; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | export const globalAgent = new Agent({ |
| 106 | keepAlive: true, |
| 107 | scheduling: 'lifo', |
| 108 | timeout: 5000, |
| 109 | }); |