Modify Response Header

In this example, an Edge Function is used to add, delete, or modify response headers.

Code

const RESOURCE_URL = 'https://data.playground.edgeone.ai/api/user/list';

async function handleRequest() {
  const response = await fetch(RESOURCE_URL);
  
  response.headers.delete('Date');

  response.headers.set('x-custom-header', 'test');
  
  response.headers.append('Server', 'edgeone');
  
  return response;
}

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

Preview

Xnip2024-07-15_17-13-50.png

References