Skip to content
This repository has been archived by the owner on Feb 7, 2023. It is now read-only.

Clarify that there are two distinct types of cf object #18

Merged
merged 1 commit into from
May 14, 2020

Conversation

ispivey
Copy link
Contributor

@ispivey ispivey commented May 10, 2020

Fixes #15.

There are two distinct cf objects associated with a Request:

  1. On an eyeball Request attached to a FetchEvent, the cf property
    contains metadata about the request, provided by Cloudflare's
    edge.
  2. As part of a dictionary of configuration passed to the Request
    constructor, the cf property allows a user to control certain
    Cloudflare functionality that can be applied to said Request,
    like image resizing.

While those two things are both objects with the key "cf", they are otherwise distinct.

This change makes these two types explicitly different, and specifies that a Request constructor's RequestInit dict can have a "cf" property that is either (1) or (2).

Previously, passing a Request object as the init arg to the Request constructor failed, because it expected a cf prop with the shape (2), and an eyeball request's cf prop has the shape of (1).

This change does not make any changes to the actual members of the cf dictionary – all the changes are whitespace and reorganization. I recommend reviewing changes ignoring whitespace: https://github.com/cloudflare/workers-types/pull/18/files?diff=unified&w=1

Fixes cloudflare#15.

There are two distinct cf objects serves associated with a Request:
1. On an eyeball Request attached to a FetchEvent, the cf property
   contains metadata about the request, provided by Cloudflare's
   edge.
2. As part of a dictionary of configuration passed to the Request
   constructor, the cf property allows a user to control certain
   Cloudflare functionality that can be applied to said Request,
   like image resizing.

While those two things are both objects in a dictionary with the
key "cf", they are otherwise distinct.

This change makes these two types explicitly different, and
specifies that a Request constructor's RequestInit dict can have
a "cf" property that is either (1) or (2).

Previously, passing a Request object as the `init` arg to the
Request constructor failed, because an eyeball request's cf prop
did not have the same shape as (2).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RequestInit and Request cf properties are different
3 participants