-
Notifications
You must be signed in to change notification settings - Fork 341
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
Should request's origin be exposed to javascript #272
Comments
I think origin belongs on the event for a couple reasons:
Overall the FetchEvent and ForeignFetchEvent objects are our way of exposing to script that a network request. Assuming that we care about the origin of the code initiating the request, then I think it makes the most sense to keep the origin on those events. |
A request already has an origin. It is most of the time initialized to "client", and updated by fetch() to match the origin of the client that called fetch(). Very similar to how the referrer of a request is dealt with (similarly initialized to "client', updated to the actual referrer when fetch() is called). And fetch already uses this origin for various CORS related checks, so all implementations should already be keeping track of this origin anyway. My question here is how the origin of the request should be exposed to javascript. |
Sure, its a book keeping item for fetch() because it doesn't have anywhere else to put it. I'm arguing it would be confusing as an exposed attribute on Request from an API point of view because you can get Request objects from places other than a fetch(). For example, constructing them directly, out of cache, etc. |
Ah, okay. Yeah, it possibly indeed makes most sense to expose the origin only on the event and not on the request itself, but it doesn't seem that different from for example the referrer. That one has the same complications with getting Request objects from places other than a fetch(). |
Actually, moving the referrer to the event objects would help with issues like #245. Maybe there is some use case for wanting the referrer in the object serialized to Cache, though. I'm not sure how people use referrer. Also, I guess you can override the referrer when creating a request and performing a fetch(). That is different from origin. I don't think we would ever want someone to change the origin of a request manually through a script exposed API. |
It would be a little weird though to expose referrer in one place and origin in another. |
Referrer can be directly initialized in the Request constructor? AFAIK, origin cannot be initialized like that. Its just always going to be "client" after construction, right? Not sure if its a real problem, but exposing origin would allow script to tell if a Request was ever fetched or not. Exposing this kind of transient state on the Request seems to muddy its API from a "object that represents a potential network request" to something like "object that represents a potential or maybe already invoked network request". Incidentally, if a service worker does |
That's a very good question... As currently spec'ed I believe it is coerced to the service worker's origin. The |
@wanderview isn't that true for referrer as wel? As for your example, not sure. In a way it might make sense to use the foreign origin there so the server knows that this is not a normal same-origin request. |
Thinking about this more I think exposing it on the |
I think this depends on when the origin is set, no? The ForeignFetchEvent.origin could be set during dispatch. I continue to dislike putting mutable state on Request, but I'll concede if you all want it there. |
I suppose that's true, although it seems a bit weird to sometimes not have the origin match the requests origin. But then it's not like a script-created foreign fetch event is going to do anything usefull anyway, so the weirdness is probably not so bad. Okay, for now I'll add an origin attribute to ForeignFetchEvent, which is initialized on dispatch rather than from from the request. |
As discussed in whatwg/fetch#272, this exposes the request's origin as an attribute separate from the request.
@wanderview you didn't really address my question though. |
Yes, I don't like that. I'd prefer not to go further down that road. I also said I would concede if you guys are in agreement with each other and want to expose it on Request. |
Perhaps related to this is w3c/ServiceWorker#899. For no-referrer requests we almost certainly don't want a foreign fetch handler to be able to read the origin of the request. So depending on if foreign fetch should be able to intercept no-referrer requests at all, the origin that is exposed to javascript might not always be able to be the same as the requests origin. |
I'm going to close this given it seems very much foreign fetch related. If there's another reason we should consider this please file a new issue, thanks! |
A request has an associated origin (usually the origin of the client that made the request). Currently for foreign fetch we expect the foreign fetch event handler to pass this origin to respondWith to explicitly expose the contents of the response to that origin. But the origin of a request isn't actually exposed to javascript. I could add an
origin
orclientOrigin
attribute toForeignFetchEvent
, but maybe it makes more sense to expose this directly for allRequest
instances?The text was updated successfully, but these errors were encountered: