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

Method constructor

source/core/index.ts:341–426  ·  view source on GitHub ↗
(url: UrlType, options?: OptionsType, defaults?: DefaultsType)

Source from the content-addressed store, hash-verified

339 private _requestInitialized = false;
340
341 constructor(url: UrlType, options?: OptionsType, defaults?: DefaultsType) {
342 super({
343 // Don't destroy immediately, as the error may be emitted on unsuccessful retry
344 autoDestroy: false,
345 // It needs to be zero because we're just proxying the data to another stream
346 highWaterMark: 0,
347 });
348
349 this.on('pipe', (source: NodeJS.ReadableStream & {headers?: Record<string, string | string[] | undefined>}) => {
350 if (this.options.copyPipedHeaders && source?.headers) {
351 const connectionListedHeaders = getConnectionListedHeaders(source.headers);
352
353 for (const [header, value] of Object.entries(source.headers)) {
354 const normalizedHeader = header.toLowerCase();
355
356 if (omittedPipedHeaders.has(normalizedHeader) || connectionListedHeaders.has(normalizedHeader)) {
357 continue;
358 }
359
360 if (!this.options.shouldCopyPipedHeader(normalizedHeader)) {
361 continue;
362 }
363
364 this.options.setPipedHeader(normalizedHeader, value);
365 }
366 }
367 });
368
369 this.on('newListener', event => {
370 if (event === 'retry' && this.listenerCount('retry') > 0) {
371 throw new Error('A retry listener has been attached already.');
372 }
373 });
374
375 try {
376 this.options = new Options(url, options, defaults);
377
378 if (!this.options.url) {
379 if (this.options.prefixUrl === '') {
380 throw new TypeError('Missing `url` property');
381 }
382
383 this.options.url = '';
384 }
385
386 this.requestUrl = this.options.url as URL;
387
388 // Publish request creation event
389 publishRequestCreate({
390 requestId: this._requestId,
391 url: getSanitizedUrl(this.options),
392 method: this.options.method,
393 });
394 } catch (error: unknown) {
395 const {options} = error as OptionsError;
396 if (options) {
397 this.options = options;
398 }

Callers

nothing calls this directly

Calls 8

_beforeErrorMethod · 0.95
publishRequestCreateFunction · 0.85
getSanitizedUrlFunction · 0.85
normalizeErrorFunction · 0.85
hasMethod · 0.80
shouldCopyPipedHeaderMethod · 0.80
setPipedHeaderMethod · 0.80

Tested by

no test coverage detected