From 41ac23d2afc833de1fd4ac3d2d4da9a9c676a386 Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Sun, 7 Jul 2024 13:03:12 +0200 Subject: [PATCH] chore(wip): log --- .../ClientRequest/utils/recordRawHeaders.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/interceptors/ClientRequest/utils/recordRawHeaders.ts b/src/interceptors/ClientRequest/utils/recordRawHeaders.ts index 70bff81a..53e74d41 100644 --- a/src/interceptors/ClientRequest/utils/recordRawHeaders.ts +++ b/src/interceptors/ClientRequest/utils/recordRawHeaders.ts @@ -5,6 +5,8 @@ const kRawHeaders = Symbol('kRawHeaders') const kRestoreHeaders = Symbol('kRestoreHeaders') function recordRawHeader(headers: Headers, args: HeaderTuple) { + console.log('recording header call:', args) + if (!Reflect.has(headers, kRawHeaders)) { Object.defineProperty(headers, kRawHeaders, { value: [], @@ -15,6 +17,7 @@ function recordRawHeader(headers: Headers, args: HeaderTuple) { const rawHeaders = Reflect.get(headers, kRawHeaders) as RawHeaders rawHeaders.push(args) + console.log('next calls:', rawHeaders) } /** @@ -32,8 +35,11 @@ function recordRawHeader(headers: Headers, args: HeaderTuple) { * h[Symbol('headers map')] // Map { 'X-Custom' => 'one, two' } */ export function recordRawFetchHeaders() { + console.log('patching headers...') + // Prevent patching the Headers prototype multiple times. if (Reflect.get(Headers, kRestoreHeaders)) { + console.log('already patched!') return Reflect.get(Headers, kRestoreHeaders) } @@ -44,6 +50,7 @@ export function recordRawFetchHeaders() { Headers.prototype.set = set Headers.prototype.append = append Headers.prototype.delete = headersDeleteMethod + console.log('Headers restored!') }, enumerable: false, }) @@ -76,10 +83,14 @@ export function recordRawFetchHeaders() { return Reflect.apply(target, thisArg, args) }, }) + console.log('patched all Headers methods!') } export function restoreHeadersPrototype() { + console.log('restoring Headers...') + if (!Reflect.get(Headers, kRestoreHeaders)) { + console.log('not patched to begin with, nothing to restore!') return }