MCPcopy Create free account
hub / github.com/nock/nock / convertFetchRequestToClientRequest

Function convertFetchRequestToClientRequest

lib/common.js:585–605  ·  view source on GitHub ↗

* @param {Request} request

(request)

Source from the content-addressed store, hash-verified

583 * @param {Request} request
584 */
585function convertFetchRequestToClientRequest(request) {
586 const url = new URL(request.url)
587 const options = {
588 ...urlToOptions(url),
589 method: request.method,
590 host: url.hostname,
591 port: url.port || (url.protocol === 'https:' ? 443 : 80),
592 path: url.pathname + url.search,
593 proto: url.protocol.slice(0, -1),
594 headers: Object.fromEntries(request.headers.entries()),
595 }
596
597 // By default, Node adds a host header, but for maximum backward compatibility, we are now removing it.
598 // However, we need to consider leaving the header and fixing the tests.
599 if (options.headers.host === options.host) {
600 const { host, ...restHeaders } = options.headers
601 options.headers = restHeaders
602 }
603
604 return new http.ClientRequest(options)
605}
606
607/**
608 * Returns true if the given value is a plain object and not an Array.

Callers

nothing calls this directly

Calls 1

urlToOptionsFunction · 0.85

Tested by

no test coverage detected