73 lines
11 KiB
JavaScript
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3BlY2lhbC1oYW5kbGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9wcm94eWxlc3MvcmVxdWVzdC1waXBlbGluZS9zcGVjaWFsLWhhbmRsZXJzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBRUEsMERBQWdFO0FBR2hFLDZEQUltQztBQUVuQyxzQ0FBeUM7QUFDekMsMkNBQTBEO0FBQzFELHlEQUFnRDtBQUNoRCxvRUFBMkM7QUFDM0MsNENBQWlEO0FBQ2pELHlDQUtvQjtBQUdwQ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