Innovenergy_trunk/frontend/node_modules/testcafe/lib/proxyless/request-hooks/event-provider.js

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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXZlbnQtcHJvdmlkZXIuanMiLCJzb3VyY2VSb290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