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

Throw an error for unimplemented fetch options #134

@iameli

Description

@iameli

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions