From 4f657edc51b55c3eade54dc85068c630b9baaa91 Mon Sep 17 00:00:00 2001 From: Krishan Thisera Date: Tue, 28 Mar 2023 17:45:06 +1030 Subject: [PATCH] Revert "JBH-615: Set is a bot header" --- .../lib/prerender-check.ts | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/packages/lambda-at-edge-handlers/lib/prerender-check.ts b/packages/lambda-at-edge-handlers/lib/prerender-check.ts index ad907410..6b4ec090 100644 --- a/packages/lambda-at-edge-handlers/lib/prerender-check.ts +++ b/packages/lambda-at-edge-handlers/lib/prerender-check.ts @@ -11,31 +11,25 @@ export const handler = async ( ): Promise => { let request = event.Records[0].cf.request; - /** - * If the request is from a bot, is not a file and is not from prerender - * then set the x-request-prerender header so the origin-request lambda function - * alters the origin to prerender.io - * "x-is-a-bot" header should be whitelisted in the respective behaviors - */ - if (IS_BOT.test(request.headers["user-agent"][0].value)) { - request.headers["x-is-a-bot"] = [ + // If the request is from a bot, is not a file and is not from prerender + // then set the x-request-prerender header so the origin-request lambda function + // alters the origin to prerender.io + if ( + !IS_FILE.test(request.uri) && + IS_BOT.test(request.headers["user-agent"][0].value) && + !request.headers["x-prerender"] + ) { + request.headers["x-request-prerender"] = [ { - key: "x-is-a-bot", + key: "x-request-prerender", value: "true", }, ]; - if (!IS_FILE.test(request.uri) && !request.headers["x-prerender"]) { - request.headers["x-request-prerender"] = [ - { - key: "x-request-prerender", - value: "true", - }, - ]; - request.headers["x-prerender-host"] = [ - { key: "X-Prerender-Host", value: request.headers.host[0].value }, - ]; - } + request.headers["x-prerender-host"] = [ + { key: "X-Prerender-Host", value: request.headers.host[0].value }, + ]; } + return request; };