Skip to content

Commit

Permalink
Merge pull request #32 from EthianWong/feat/enhance-cookie-catch
Browse files Browse the repository at this point in the history
feat: enhanced cookie capture capabilities
  • Loading branch information
GrinZero authored Nov 19, 2024
2 parents 6c0f3d2 + 437d197 commit 6349b40
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/network-debugger/src/core/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,21 @@ function proxyCallbackFactory(
}
}

function proxySetCookie(
request: ClientRequest,
mainProcess: MainProcess,
requestDetail: RequestDetail
) {
let originSetHeader = request.setHeader
request.setHeader = function (name, val) {
if (name.toLowerCase() === 'cookie') {
requestDetail.requestHeaders.cookie = val.toString()
mainProcess.updateRequest(requestDetail)
}
return originSetHeader.call(request, name, val)
}
}

export function requestProxyFactory(
this: any,
actualRequestHandler: any,
Expand Down Expand Up @@ -219,10 +234,12 @@ export function requestProxyFactory(
options as RequestOptions,
proxyCallback
)
proxySetCookie(request, mainProcess, requestDetail)
return proxyClientRequestFactory(request, requestDetail, mainProcess)
} else {
// Call actualRequestHandler with 2 parameters
const request: ClientRequest = actualRequestHandler(options as RequestOptions, proxyCallback)
proxySetCookie(request, mainProcess, requestDetail)
return proxyClientRequestFactory(request, requestDetail, mainProcess)
}
}
Expand Down

0 comments on commit 6349b40

Please sign in to comment.