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

Use the fetched unsafe response for network status and response bodies #9362

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

trflynn89
Copy link

@trflynn89 trflynn89 commented May 30, 2023

After using Fetch infrastructure to retrieve a resource, go through the response's unsafe response to inspect the network status of the response and read its body. When the response is CORS-cross-origin, Fetch will provide an opaque filtered response, which will always have a null body and network status of 0.

Fixes #9355

  • At least two implementers are interested (and none opposed):
  • Tests are written and can be reviewed and commented upon at:
  • Implementation bugs are filed:
    • Chromium: …
    • Gecko: …
    • WebKit: …
    • Deno (only for timers, structured clone, base64 utils, channel messaging, module resolution, web workers, and web storage): …
    • Node.js (only for timers, structured clone, base64 utils, channel messaging, and module resolution): …
  • MDN issue is filed: …

(See WHATWG Working Mode: Changes for more details.)


/acknowledgements.html ( diff )
/links.html ( diff )
/media.html ( diff )
/semantics.html ( diff )

source Outdated
@@ -35843,6 +35845,8 @@ interface <dfn interface>MediaError</dfn> {
<span data-x="concept-response">response</span> <var>response</var>:</p>

<ol>
<li><p>Set <var>response</var> to <var>response</var>'s <span>unsafe response</span>.</p></li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is right. Later, e.g. here, we check if the response is CORS-cross-origin. This would return false for the internal response. We should only unwrap the internal response when actually wanting to use the data - e.g. when decoding, presenting etc.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that's right. I've updated HTMLMediaElement to use the unsafe response just when reading its body.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the same applies to images though

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For images, there weren't really any spec steps that run on response directly, it just originally said "The resource obtained in this fashion, if any, is image request's image data".

For links, it seemed like all downstream users also need the unsafe response, as it's used when:

I can update those to instead all check the unsafe response's status / Content-Type inline, if that's preferable.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, but for CSS links, we do need to know downstream if it is CORS-same-origin, so I'll go ahead and inline the use of unsafe response.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but later there are places where we check if image data is CORS-cross-origin. So we should assume image-data is something response-like (this should really be refactored) and use the unsafe response only when we need direct access to the data

After using Fetch infrastructure to retrieve a resource, go through the
response's unsafe response to inspect the network status of the response
and read its body. When the response is CORS-cross-origin, Fetch will
provide an opaque filtered response, which will always have a null body
and network status of 0.
@annevk
Copy link
Member

annevk commented Jun 9, 2023

@trflynn89 could you look into signing https://participate.whatwg.org/agreement? We'll need that eventually in order to be able to merge the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants