MCPcopy
hub / github.com/sindresorhus/got / createNativeRequestOptions

Method createNativeRequestOptions

source/core/options.ts:3284–3371  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3282 }
3283
3284 createNativeRequestOptions() {
3285 const internals = this.#internals;
3286 const url = internals.url as URL;
3287
3288 let agent;
3289 if (url.protocol === 'https:') {
3290 if (internals.http2) {
3291 // Ensure HTTP/2 agent is configured for connection reuse
3292 // If no custom agent.http2 is provided, use the global agent for connection pooling
3293 agent = {
3294 ...internals.agent,
3295 http2: internals.agent.http2 ?? http2wrapper.globalAgent,
3296 };
3297 } else {
3298 agent = internals.agent.https;
3299 }
3300 } else {
3301 agent = internals.agent.http;
3302 }
3303
3304 const {https} = internals;
3305 let {pfx} = https;
3306
3307 if (is.array(pfx) && is.plainObject(pfx[0])) {
3308 pfx = (pfx as PfxObject[]).map(object => ({
3309 buf: object.buffer,
3310 passphrase: object.passphrase,
3311 })) as any;
3312 }
3313
3314 const unixSocketPath = getUnixSocketPath(url);
3315
3316 if (usesUnixSocket(url) && !internals.enableUnixSockets) {
3317 throw new Error('Using UNIX domain sockets but option `enableUnixSockets` is not enabled');
3318 }
3319
3320 let unixSocketGroups: {socketPath: string; path: string} | undefined;
3321
3322 if (unixSocketPath !== undefined) {
3323 unixSocketGroups = /^(?<socketPath>[^:]+):(?<path>.+)$/v.exec(`${url.pathname}${url.search}`)?.groups as typeof unixSocketGroups;
3324 }
3325
3326 const unixOptions = unixSocketGroups
3327 ? {socketPath: unixSocketGroups.socketPath, path: unixSocketGroups.path, host: ''}
3328 : undefined;
3329
3330 return {
3331 ...internals.cacheOptions,
3332 ...unixOptions,
3333
3334 // HTTPS options
3335 // eslint-disable-next-line @typescript-eslint/naming-convention
3336 ALPNProtocols: https.alpnProtocols,
3337 ca: https.certificateAuthority,
3338 cert: https.certificate,
3339 key: https.key,
3340 passphrase: https.passphrase,
3341 pfx,

Callers 3

_makeRequestMethod · 0.80
create.tsFile · 0.80
unix-socket.tsFile · 0.80

Calls 3

getUnixSocketPathFunction · 0.85
usesUnixSocketFunction · 0.85
getHttp2TimeoutOptionFunction · 0.85

Tested by

no test coverage detected