52 lines
9.3 KiB
JavaScript
52 lines
9.3 KiB
JavaScript
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
const testcafe_hammerhead_1 = require("testcafe-hammerhead");
|
||
|
const string_1 = require("../utils/string");
|
||
|
const cdp_1 = require("../utils/cdp");
|
||
|
class ProxylessRequestHookEventProvider extends testcafe_hammerhead_1.RequestHookEventProvider {
|
||
|
static _hasResponseWithBody(context) {
|
||
|
return context.onResponseEventData.some((eventData) => eventData.opts.includeBody);
|
||
|
}
|
||
|
static async _setResponseBody({ pipelineContext, resourceBody, eventFactory, event, client }) {
|
||
|
if ((resourceBody === null || resourceBody === void 0 ? void 0 : resourceBody.length) || (0, cdp_1.isPreflightRequest)(event)) {
|
||
|
eventFactory.setResponseBody(resourceBody);
|
||
|
return;
|
||
|
}
|
||
|
const hasOnResponseWithBody = ProxylessRequestHookEventProvider._hasResponseWithBody(pipelineContext);
|
||
|
if (!hasOnResponseWithBody)
|
||
|
return;
|
||
|
const responseObj = await client.Fetch.getResponseBody({ requestId: event.requestId });
|
||
|
const responseBody = (0, string_1.getResponseAsBuffer)(responseObj);
|
||
|
eventFactory.setResponseBody(responseBody);
|
||
|
}
|
||
|
async onRequest(event, contextInfo) {
|
||
|
if (!this.hasRequestEventListeners())
|
||
|
return;
|
||
|
const { pipelineContext, eventFactory } = contextInfo.getContextData(event);
|
||
|
await pipelineContext.onRequestHookRequest(this, eventFactory);
|
||
|
}
|
||
|
async onResponse(event, resourceBody, contextInfo, client) {
|
||
|
let modified = false;
|
||
|
if (!this.hasRequestEventListeners())
|
||
|
return modified;
|
||
|
const { pipelineContext, eventFactory } = contextInfo.getContextData(event);
|
||
|
eventFactory.update(event);
|
||
|
await pipelineContext.onRequestHookConfigureResponse(this, eventFactory);
|
||
|
if (eventFactory.headersModified)
|
||
|
modified = true;
|
||
|
await ProxylessRequestHookEventProvider._setResponseBody({
|
||
|
pipelineContext,
|
||
|
resourceBody,
|
||
|
eventFactory,
|
||
|
event,
|
||
|
client,
|
||
|
});
|
||
|
await Promise.all(pipelineContext.onResponseEventData.map(async (eventData) => {
|
||
|
await pipelineContext.onRequestHookResponse(this, eventFactory, eventData.rule, eventData.opts);
|
||
|
}));
|
||
|
return modified;
|
||
|
}
|
||
|
}
|
||
|
exports.default = ProxylessRequestHookEventProvider;
|
||
|
module.exports = exports.default;
|
||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXZlbnQtcHJvdmlkZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvcHJveHlsZXNzL3JlcXVlc3QtaG9va3MvZXZlbnQtcHJvdmlkZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSw2REFJNkI7QUFJN0IsNENBQXNEO0FBQ3RELHNDQUFrRDtBQUtsRCxNQUFxQixpQ0FBa0MsU0FBUSw4Q0FBd0I7SUFDM0UsTUFBTSxDQUFDLG9CQUFvQixDQUFFLE9BQWlDO1FBQ2xFLE9BQU8sT0FBTyxDQUFDLG1CQUFtQixDQUFDLElBQUksQ0FBQyxDQUFDLFNBQThCLEVBQUUsRUFBRSxDQUFDLFNBQVMsQ0FBQyxJQUFJLENBQUMsV0FBVyxDQUFDLENBQUM7SUFDNUcsQ0FBQztJQUVPLE1BQU0sQ0FBQyxLQUFLLENBQUMsZ0JBQWdCLENBQUUsRUFBRSxlQUFlLEVBQUUsWUFBWSxFQUFFLFlBQVksRUFBRSxLQUFLLEVBQUUsTUFBTSxFQUF5SztRQUN4USxJQUFJLENBQUEsWUFBWSxhQUFaLFlBQVksdUJBQVosWUFBWSxDQUFFLE1BQU0sS0FBSSxJQUFBLHdCQUFrQixFQUFDLEtBQUssQ0FBQyxFQUFFO1lBQ2xELFlBQW9ELENBQUMsZUFBZSxDQUFDLFlBQXNCLENBQUMsQ0FBQztZQUU5RixPQUFPO1NBQ1Y7UUFHRCxNQUFNLHFCQUF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