Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing platform-specific meta information with the Request/Response instances #8

Open
maxshirshin opened this issue Jun 28, 2022 · 2 comments

Comments

@maxshirshin
Copy link

Platforms like Cloudflare Workers or Shopify Oxygen may need to add additional information to requests/responses. Cloudflare Workers has a proprietary .cf property which includes fields like geolocation data etc. Shopify's Oxygen runtime has similar needs but uses custom HTTP headers to pass the data.

Since the standard doesn't offer any way to pass extra meta information along with Request/Response instances, it would be great to explore these and similar scenarios to see how the extra meta data may be added. There likely were no use cases for this in the browser world, but on the server side, the situation is different.

Using extra HTTP custom headers might be the most obvious approach, but it has a clear downside that headers have tight size limits, aren't very suitable for holding complex data, and can't contain anything that isn't directly serialisable into a string.

A custom property like .meta or .metadata (which should hold a JavaScript object, leaving its fields up to the vendor implementation) would be more flexible but needs to be standardised.

@jimmywarting
Copy link

I do not think Request or Response should have a custom meta property... there are other ways to go around it... like emitting a event that may include both a cf and a request property { cf: { ... }, request: new Request( ... ) }

there is also the possibility to hook in other meta property and bind it to request without actually modifying the request...
you could use WeakMap to bind other meta data to it.

const wm = new WeakMap()
const req = new Request( ... )
const cf = { country: 'sweden' }

wm.set(req, cf)
wm.get(req) // return custom meta associated to the request 

@blittle
Copy link

blittle commented Jun 29, 2022

This might belong in the environment-metadata work stream.

@Ethan-Arrowood Ethan-Arrowood transferred this issue from another repository Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants