Random Content Cookies

You can create random content cookies using Cloudflare Workers.

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

async function fetchAndApply(request) {
  const response = await fetch(request)

  const modifiedHeaders = new Headers(response.headers)
  const randomStuff = `randomcookie=${Math.random()}; Expires=Wed, 21 Oct 2018 07:28:00 GMT; Path='/';`

  modifiedHeaders.set('Set-Cookie', randomStuff)

  const init = {
    status: response.status,
    statusText: response.statusText,
    headers: modifiedHeaders
  }

  const modifiedResponse = new Response(response.body, init)
  return response
}