Using a Worker to return an unoptimized image

On my primary domain, I would like to have the Polish and WEBP features enabled. I think these are great features, especially since we allow users to upload their own images, and all of the optimization is handled automatically for us.

However, we also want to allow a user’s original image to be downloaded to be used in other applications. We have a Worker that adds a “Content-Disposition” response header, to facilitate the download of the image. However, with Polish and/or WEBP enabled, the image that is returned to the user is not in the original JPG format.

Here’s the code that I have tried thus far, but the images still get returned as a WEBP or AVIC file.

addEventListener("fetch", (event) => {
  event.respondWith(
    handleRequest(event.request).catch(
      (err) => new Response(err.stack, { status: 500 })
    )
  );
});

async function handleRequest(request) {

  // get request info
  const { pathname, searchParams } = new URL(request.url);

  // setup headers
  let headers = { 
    'accept': 'image/jpg,image/png,image/gif,video/mp4,application/pdf', 
    'cache-control': 'no-transform', 
    'user-agent': 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko' 
  };
  
  // get image
  const proxy = await fetch('https://[MY DOMAIN]' + pathname, { cf: { cacheTtl: 0, polish: 'off' }, headers: headers });
  
  // copy response and download header
  let response = new Response(proxy);
  let filename = searchParams.get('filename').replace(/[^0-9a-zA-Z. _\-]/g, '');
  response.headers.set('content-disposition', 'attachment; filename=' + filename);

  // done
  return response; 

}

Any ideas on how I can force the fetch() to return an unmodified image when that feature is enabled on the domain?

Thank you, for any insights!