Can someone verify Cloudflare Worker Headers? - Very Useful Scripts Included

This is my first time working with Cloudflare Workers, however I have put together some very useful scripts for my Wordpress website that I would like to share with the community. SEM Rush is reporting hundreds of 302 redirect loop errors and now my curiosity has be concerned that this might be due to the headers in my Cloudflare workers. Hoping to get some validation or verification with what I am doing here.

Thank you,

addEventListener('fetch', event => {
    event.passThroughOnException()
    event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
  const country = request.cf.country
  let cookies = request.headers.get('Cookie') || ""
  const url = new URL(request.url)
  let response = await fetch(request);
  response = new Response(response.body, response);

// Set Cookie if the country is not United States or Canada
  if ((country != 'US' && country !='CA')) {
response.headers.set('Set-Cookie', "pricing-mode=on;max-age=604800;Path=/");
return response;
}

// Set Cookie if the url contains gclid, bing, fbclid, or pricing
else if ((url.search.includes("gclid")) || (url.search.includes("bing")) || (url.search.includes("fbclid")) || (url.pathname.includes("pricing"))) {

response.headers.set('Set-Cookie', "pricing-mode=on;max-age=604800;Path=/");
return response;
}

// Adjust Styling if Cookie Exists
  else if ((cookies.includes("pricing-mode=on"))) {
    const response = await fetch(request)
    const type = response.headers.get("Content-Type") || "";
    if (!type.startsWith("text/html")) {
     return response;
   }
    var html = await response.text()
    
    // Inject scripts
    const customMenu = '<style type="text/css">STYLING HERE</style></body>'
  html = html.replace( /<\/body>/ , customMenu)

    // return modified response
       return new Response(html, response)
}

// Do Nothing
 else {
     return fetch(request)
  }
}