Skip to content

Commit

Permalink
chore(wip): log
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Jul 7, 2024
1 parent 50bdac0 commit 41ac23d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/interceptors/ClientRequest/utils/recordRawHeaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand All @@ -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)
}

/**
Expand All @@ -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)
}

Expand All @@ -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,
})
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 41ac23d

Please sign in to comment.