Modify Request Header

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

Code

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

async function handleRequest() {
  const newRequest = new Request(RESOURCE_URL);

  newRequest.headers.set('x-custom-header', 'test');
  
  newRequest.headers.append('x-edge-client', 'edgeone');

  const response = await fetch(newRequest);

  return response;
}

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

Preview

Xnip2024-07-15_17-17-40.png

References