Saving headers when changing url

Hello, here is the problem.

I need fetch other site saving original headers, so when I put

const resp = await fetch(event.request);

all working fine, when I change to

const resp = await fetch("https://httpbin.org/get"); 

all my initial headers is lost.

I understand that I need to copy initial headers like described in … /workers//runtime-apis/request#requestinit but don’t have idea how to do it, because

const newRequestInit = {
    headers: event.request.headers
  };

or similar - not working, or I doing something wrong

How I can transfer all old headers to now request?

1 Like

Just pass the original request to the RequestInit of the fetch.

const resp = await fetch("https://httpbin.org/get", request);
1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.