This repository has been archived by the owner on Nov 30, 2024. It is now read-only.
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.
Request/Response browser differences #6
Open
Description
Currently, both the Request
and Response
classes contain a bunch of properties that likely have no effect server-side.
Request:
request.destination
request.referrer
request.referrerPolicy
request.mode
*request.cache
"...indicating how the request will interact with the browser’s cache when fetching"request.integrity
"A cryptographic hash of the resource to be fetched by request."request.isReloadNavigation
request.isHistoryNavigation
RequestInit
(options that are passed to the Request
constructor)
RequestInit.referrer
: "A string whose value is a same-origin URL"RequestInit.referrerPolicy
: "A referrer policy to set request’s referrerPolicy."RequestInit.mode
: "A string to indicate whether the request will use CORS, or will be restricted to same-origin URLs. Sets request’s mode. If input is a string, it defaults to "cors"."RequestInit.credentials
: seerequest.credentials
*RequestInit.cache
: seerequest.cache
RequestInit.integrity
: seerequest.integrity
RequestInit.window
: "Can only be null. Used to disassociate request from any Window."
Response
* omit
and include
may be useful for developers, however same-origin
is not.
** cors
should be omitted from this type.
Implementations:
- node.js: implements "everything" according to the spec (even things that aren't relevant to a server environment).
- Deno: https://deno.land/manual/runtime/web_platform_apis#fetch-api
- node-fetch: https://github.com/node-fetch/node-fetch#class-request
- Cloudflare workers: https://developers.cloudflare.com/workers//runtime-apis/request#requestinit https://developers.cloudflare.com/workers//runtime-apis/request#properties
Aligning Behavior
As you can see, each environment is different in supported properties which can cause cross-platform confusion. It also makes everything more confusing considering that these platforms typically leave in unsupported properties in their typings, but do not document which types are ignored (unless you look for it on google).
Potential Solutions:
- Choose default values to return for useless flags (for example, node.js' Request class will always return
false
forrequest.isHistoryNavigation
). Default flags would also be needed forRequestInit
as the spec heavily defines fetch's behavior from certain flags being set. - Fork the fetch spec and remove mentions of these flags, along with conditions that would no longer be possible with said flags being removed. This would be a lot of work.
- Create a new document that would supersede certain steps/behaviors in the fetch spec. For example:
<-- Original fetch spec -->
# some title
1. If request's mode is "cors" then:
...
2. Perform scheme fetch.
3. If request's `referrer` is not this's current settings origin url then:
1. Abort this request.
2. Return a network error.
// and so on
<-- Server environment spec -->
# some title
1. Ignore step 1
3. Ignore step 3
// and so on
Metadata
Assignees
Labels
No labels
Activity