Add custom headers to 301 redirect in workers

#1

Hey guys,
I am trying to do a 301 redirect from domain A to domain B, so far so good :slight_smile:
However I want to pass custom headers along with it and I am not sure how to do that… Some help would be appreciated!

My code on domain A:

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

async function handleRedirectTo(request) {
  let redirectHeaders = new Headers()
  redirectHeaders.set('Location', 'https://Domain-B.com')
  redirectHeaders.set('x-from-Domain-A', 'true')

  return new Response('', {
			status: 302,
			headers: redirectHeaders
		})
}

And my code on domain B:

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

async function handleRedirectFrom(request) {
  let response = await fetch(request)
  console.log(response.headers.get("x-from-Domain-A"))
  return response
}