{"action":"created","issue":{"url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/841","repository_url":"https://api.github.com/repos/slightlyoff/ServiceWorker","labels_url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/841/labels{/name}","comments_url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/841/comments","events_url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/841/events","html_url":"https://github.com/slightlyoff/ServiceWorker/issues/841","id":136172302,"number":841,"title":"Define some way for foreign fetch to decide on opaqueness of responses","user":{"login":"mkruisselbrink","id":5649,"avatar_url":"https://avatars.githubusercontent.com/u/5649?v=3","gravatar_id":"","url":"https://api.github.com/users/mkruisselbrink","html_url":"https://github.com/mkruisselbrink","followers_url":"https://api.github.com/users/mkruisselbrink/followers","following_url":"https://api.github.com/users/mkruisselbrink/following{/other_user}","gists_url":"https://api.github.com/users/mkruisselbrink/gists{/gist_id}","starred_url":"https://api.github.com/users/mkruisselbrink/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkruisselbrink/subscriptions","organizations_url":"https://api.github.com/users/mkruisselbrink/orgs","repos_url":"https://api.github.com/users/mkruisselbrink/repos","events_url":"https://api.github.com/users/mkruisselbrink/events{/privacy}","received_events_url":"https://api.github.com/users/mkruisselbrink/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/slightlyoff/ServiceWorker/milestones/3","html_url":"https://github.com/slightlyoff/ServiceWorker/milestones/Version%202","labels_url":"https://api.github.com/repos/slightlyoff/ServiceWorker/milestones/3/labels","id":825216,"number":3,"title":"Version 2","description":null,"creator":{"login":"KenjiBaheux","id":6354698,"avatar_url":"https://avatars.githubusercontent.com/u/6354698?v=3","gravatar_id":"","url":"https://api.github.com/users/KenjiBaheux","html_url":"https://github.com/KenjiBaheux","followers_url":"https://api.github.com/users/KenjiBaheux/followers","following_url":"https://api.github.com/users/KenjiBaheux/following{/other_user}","gists_url":"https://api.github.com/users/KenjiBaheux/gists{/gist_id}","starred_url":"https://api.github.com/users/KenjiBaheux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KenjiBaheux/subscriptions","organizations_url":"https://api.github.com/users/KenjiBaheux/orgs","repos_url":"https://api.github.com/users/KenjiBaheux/repos","events_url":"https://api.github.com/users/KenjiBaheux/events{/privacy}","received_events_url":"https://api.github.com/users/KenjiBaheux/received_events","type":"User","site_admin":false},"open_issues":34,"closed_issues":20,"state":"open","created_at":"2014-10-14T08:25:32Z","updated_at":"2016-02-25T09:48:18Z","due_on":null,"closed_at":null},"comments":7,"created_at":"2016-02-24T20:05:29Z","updated_at":"2016-02-26T10:09:53Z","closed_at":null,"body":"A service worker with a foreign fetch handler needs some kind of API to decide if responses it returns should be opaque responses or not when received by whoever initiated the fetch (as currently specified all responses will be opaque, which is rather limiting).\r\n \r\nCurrently [proposed](https://github.com/mkruisselbrink/ServiceWorker/blob/foreign-fetch/foreign_fetch_explainer.md#what-about-cors) is that by default all responses from a foreign fetch handler should be opaque, and we'll have some extra API to explicitly mark a response as non-opaque (assuming the response isn't already opaque to the service worker itself). The proposed API allows you to associate two bits of information with a response: \r\n\r\n1. the origin to which the response should be exposed (similar to Access-Control-Allow-Origin in CORS, but not allowing wildcards), and\r\n2. (optionally) which headers of the response should be exposed (similar to Access-Control-Expose-Headers in CORS)\r\n\r\nOf course that leaves the question why we don't just require the foreign fetch handler to set these CORS headers on their responses, rather then coming up with our own API. I don't quite remember what the arguments for this were (changing headers requires returning a synthetic response, which might behave differently? slightly more complicated code to write to be able to return a synthetic response? semantics are subtly different from CORS so re-using CORS headers isn't ideal? explicit API is just easier to use?)\r\n\r\nBut assuming we do indeed want some kind of API to mark a response as being non-opaque for the purpose of foreign fetch, what should that API look like?\r\n\r\nAs proposed:\r\n```idl\r\npartial interface Response {\r\n  static Promise<VisibleResponse> makeVisibleTo(promise<Response>,\r\n      USVString origin, optional ResponseVisibilityOptions options);\r\n};\r\n\r\ndictionary ResponseVisibilityOptions {\r\n  sequence<USVString> headers;\r\n};\r\n\r\n// TODO: define VisibleResponse\r\n```\r\ncombined with changing `respondWith` to accept a `Promise<Response or VisibleResponse>` (for a regular fetch event calling makeVisibleTo on the response passed to respondWith wouldn't change any behavior).\r\n\r\nThe `makeVisibleTo` method could of course also be a method on the `FetchEvent` (and there is also the question if foreign fetch should keep using the same `FetchEvent` interface or have its own `ForeignFetchEvent` interface that might or might not derive from `FetchEvent`).\r\n\r\nAnother option might be to change `respondWith` to be able to be called asynchronously (as long as `waitUntil` promises haven't all resolved yet) and just add the new visibility options as an extra argument to respondWith.\r\n\r\n/cc @slightlyoff @annevk "},"comment":{"url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/comments/189203949","html_url":"https://github.com/slightlyoff/ServiceWorker/issues/841#issuecomment-189203949","issue_url":"https://api.github.com/repos/slightlyoff/ServiceWorker/issues/841","id":189203949,"user":{"login":"annevk","id":1544111,"avatar_url":"https://avatars.githubusercontent.com/u/1544111?v=3","gravatar_id":"","url":"https://api.github.com/users/annevk","html_url":"https://github.com/annevk","followers_url":"https://api.github.com/users/annevk/followers","following_url":"https://api.github.com/users/annevk/following{/other_user}","gists_url":"https://api.github.com/users/annevk/gists{/gist_id}","starred_url":"https://api.github.com/users/annevk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/annevk/subscriptions","organizations_url":"https://api.github.com/users/annevk/orgs","repos_url":"https://api.github.com/users/annevk/repos","events_url":"https://api.github.com/users/annevk/events{/privacy}","received_events_url":"https://api.github.com/users/annevk/received_events","type":"User","site_admin":false},"created_at":"2016-02-26T10:09:53Z","updated_at":"2016-02-26T10:09:53Z","body":"respondWith() cannot simply unwrap. It needs to be a new filtered response of some kind. Otherwise it would reveal all of the response whereas we want to limit exposure to certain headers and such (and we also don't want to expose more headers than were exposed thus far, might be quite tricky to get that right)."}}