in src/policy.ts [336:380]
export async function processRequest(context: RecaptchaContext, req: EdgeRequest): Promise<EdgeResponse> {
const actions = await fetchActions(context, req);
context.log_performance_debug("[func] applyActions - start");
let resp = applyActions(context, req, actions);
context.log_performance_debug("[func] applyActions - end");
// Create a response that dumps the exceptions and log messages.
// This response will look like a JSON object like { logs: ["log msg 1", "log msg 2"], exceptions: ["exception1"]}
// This is used solely for debugging, and will replace the expected response.
// This is unsafe and should never be used in production, as it overwrites the response.
// The logs dumped here are much more substantial than the debug response header populated with the 'debug' flag.
if (context.config.unsafe_debug_dump_logs) {
await resp;
resp = Promise.resolve(
context.createResponse(
JSON.stringify(
{
logs: context.log_messages,
exceptions: context.exceptions,
list_firewall_policies_headers: Array.from(
(context.debug_trace._list_firewall_policies_headers ?? new Map()).entries(),
),
create_assessment_headers: Array.from(
(context.debug_trace._create_assessment_headers ?? new Map()).entries(),
),
},
null,
2,
),
),
);
}
// Create a debug response header.
// This header has some useful stats like what action was chose, what site key was used, how many policies were loaded, etc.
if (context.config.debug) {
let resolved_resp = await resp;
context.debug_trace.exception_count = context.exceptions.length;
resolved_resp.addHeader("X-RECAPTCHA-DEBUG", context.debug_trace.formatAsHeaderValue());
resp = Promise.resolve(resolved_resp);
}
return resp;
// TODO: post return call analytics
}