Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Throw an error for unimplemented fetch options #134

Open
iameli opened this issue Dec 29, 2019 · 0 comments
Open

Throw an error for unimplemented fetch options #134

iameli opened this issue Dec 29, 2019 · 0 comments

Comments

@iameli
Copy link

iameli commented Dec 29, 2019

CloudFlare Workers don't implement a variety of fields in the fetch options dict. The ones I know about are credentials, referrer, referrerPolicy, and mode. Here's a minimal example:

addEventListener("fetch", event => {
  event.respondWith(doFetch(event.request));
});

async function doFetch(request) {
  try {
    const res = await fetch(
    "https://gist.githubusercontent.com/iameli/2d9fd917a1235bb5854cca4b962a7c09/raw/f37c19b8fe5e57340ea7a874effb6b575f6b28ad/example-content.txt",
      {
        credentials: "include",
        referrer: "http://example.com",
        referrerPolicy: "no-referrer-when-downgrade",
        mode: "cors"
      }
    );
    const text = await res.text();
    return new Response(text);
  } catch (e) {
    return new Response(e.stack, { status: 500 });
  }
}

This example runs in cloudworker but fails in the CloudFlare worker itself, with an error like

Error: The 'mode' field on 'RequestInitializerDict' is not implemented.
    at doFetch (worker.js:7:23)
    at worker.js:2:21

Usually this happens when I'm being lazy and copying a fetch() from the V8 inspector — I don't actually need the fields for anything. But we should probably copy CF's behavior here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant