Innovenergy_trunk/frontend/node_modules/testcafe/lib/proxyless/request-pipeline/special-handlers.js

73 lines
11 KiB
JavaScript

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const injectables_1 = require("../../assets/injectables");
const debug_loggers_1 = require("../../utils/debug-loggers");
const cdp_1 = require("../utils/cdp");
const constants_1 = require("./constants");
const http_status_codes_1 = require("http-status-codes");
const load_assets_1 = __importDefault(require("../../load-assets"));
const string_1 = require("../utils/string");
const safe_api_1 = require("./safe-api");
const internalRequest = {
condition: (event) => !event.networkId && event.resourceType !== 'Document',
handler: async (event, client) => {
(0, debug_loggers_1.requestPipelineInternalRequestLogger)('%r', event);
await (0, safe_api_1.safeFailRequest)(client, event);
},
};
const serviceRequest = {
condition: (event, options, serviceRoutes) => {
const url = event.request.url;
// NOTE: the service 'Error page' should be proxied.
if (url === serviceRoutes.errorPage1
|| url === serviceRoutes.errorPage2)
return false;
return options.serviceDomains.some(domain => url.startsWith(domain));
},
handler: async (event, client) => {
(0, debug_loggers_1.requestPipelineServiceRequestLogger)('%r', event);
if ((0, cdp_1.isRequest)(event))
await (0, safe_api_1.safeContinueRequest)(client, event);
else
await (0, safe_api_1.safeContinueResponse)(client, event);
},
};
const defaultFaviconRequest = {
condition: (event) => {
const parsedUrl = new URL(event.request.url);
return parsedUrl.pathname === injectables_1.DEFAULT_FAVICON_PATH;
},
handler: async (event, client, options) => {
(0, debug_loggers_1.requestPipelineLogger)('%r', event);
if ((0, cdp_1.isRequest)(event))
await (0, safe_api_1.safeContinueRequest)(client, event);
else {
if (event.responseStatusCode === http_status_codes_1.StatusCodes.NOT_FOUND) { // eslint-disable-line no-lonely-if
const { favIcon } = (0, load_assets_1.default)(options.developmentMode);
await (0, safe_api_1.safeFulfillRequest)(client, {
requestId: event.requestId,
responseCode: http_status_codes_1.StatusCodes.OK,
responseHeaders: [constants_1.FAVICON_CONTENT_TYPE_HEADER],
body: (0, string_1.toBase64String)(favIcon),
});
}
else
await (0, safe_api_1.safeContinueResponse)(client, event);
}
},
};
const SPECIAL_REQUEST_HANDLERS = [
internalRequest,
serviceRequest,
defaultFaviconRequest,
];
function getSpecialRequestHandler(event, options, serviceRoutes) {
const specialRequestHandler = SPECIAL_REQUEST_HANDLERS.find(h => h.condition(event, options, serviceRoutes));
return specialRequestHandler ? specialRequestHandler.handler : null;
}
exports.default = getSpecialRequestHandler;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3BlY2lhbC1oYW5kbGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9wcm94eWxlc3MvcmVxdWVzdC1waXBlbGluZS9zcGVjaWFsLWhhbmRsZXJzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBRUEsMERBQWdFO0FBR2hFLDZEQUltQztBQUVuQyxzQ0FBeUM7QUFDekMsMkNBQTBEO0FBQzFELHlEQUFnRDtBQUNoRCxvRUFBMkM7QUFDM0MsNENBQWlEO0FBQ2pELHlDQUtvQjtBQUdwQixNQUFNLGVBQWUsR0FBRztJQUNwQixTQUFTLEVBQUUsQ0FBQyxLQUF5QixFQUFXLEVBQUUsQ0FBQyxDQUFDLEtBQUssQ0FBQyxTQUFTLElBQUksS0FBSyxDQUFDLFlBQVksS0FBSyxVQUFVO0lBQ3hHLE9BQU8sRUFBSSxLQUFLLEVBQUUsS0FBeUIsRUFBRSxNQUFtQixFQUFpQixFQUFFO1FBQy9FLElBQUEsb0RBQW9DLEVBQUMsSUFBSSxFQUFFLEtBQUssQ0FBQyxDQUFDO1FBRWxELE1BQU0sSUFBQSwwQkFBZSxFQUFDLE1BQU0sRUFBRSxLQUFLLENBQUMsQ0FBQztJQUN6QyxDQUFDO0NBQ2MsQ0FBQztBQUVwQixNQUFNLGNBQWMsR0FBRztJQUNuQix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