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

Add fetch monkeypatches to subresource-loading spec #708 #715

Merged
merged 6 commits into from
Mar 7, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 155 additions & 7 deletions subresource-loading.bs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,30 @@ Repository: WICG/webpackage
URL: https://wicg.github.io/webpackage/subresource-loading.html
Editor: Hayato Ito, Google Inc. https://google.com/, [email protected]
Abstract: How UAs load subresources from Web Bundles.

Complain About: accidental-2119 yes, missing-example-ids yes
Markup Shorthands: markdown yes, css no
Assume Explicit For: yes
</pre>
<pre class='biblio'>
{
"draft-yasskin-wpack-bundled-exchanges": {
"href": "https://wicg.github.io/webpackage/draft-yasskin-wpack-bundled-exchanges.html",
hayatoito marked this conversation as resolved.
Show resolved Hide resolved
"title": "Web Bundles"
}
}
</pre>
<pre class='anchors'>
spec: fetch; urlPrefix: https://fetch.spec.whatwg.org/#
type: dfn
text: fetch params; url: fetch-params
</pre>
<pre class="link-defaults">
spec:fetch; type:dfn; for:/; text:request
spec:fetch; type:dfn; for:/; text:response
spec:html; type:element; text:link
spec:url; type:dfn; for:/; text:url
</pre>

<section class="non-normative">

# Introduction # {#intro}

<em>This section is non-normative.</em>
Expand All @@ -31,7 +43,143 @@ specification describes how web browsers load those resources. It is expressed
as several monkeypatches to the [[HTML]] and [[FETCH]] specification which call
algorithms defined here.

<p class="note">
This specification is under construct. See
<a href="https://github.com/WICG/webpackage/issues/708">#708</a>.
</p>
Note: This specification is under construct. See <a href="https://github.com/WICG/webpackage/issues/708">#708</a>.

# Structures # {#structures}

A <dfn>fetched web bundle</dfn> is a representation of a web bundle format
defined in [[draft-yasskin-wpack-bundled-exchanges]].

A <dfn>bundle rule</dfn> is a [=struct=] with the following
[=struct/items=]:

- <dfn for="bundle rule">source</dfn>, a [=URL=].
- <dfn for="bundle rule">credentials</dfn>, a [=request/mode=].
hayatoito marked this conversation as resolved.
Show resolved Hide resolved
- <dfn for="bundle rule">resources</dfn>, a list of [=URLs=].
- <dfn for="bundle rule">scopes</dfn>, a list of [=URLs=].

A <dfn>web bundle</dfn> is a [=struct=] with the following [=struct/items=]:

- <dfn for="web bundle">fetched bundle</dfn>, a [=fetched web bundle=] or null.
- <dfn for="web bundle">rule</dfn>, a [=bundle rule=].
- <dfn for="web bundle">state</dfn>, an internal state which is "fetching", "fetched", or "failed". Initially "fetching".

# New Document fields # {#new-document-fields}

A {{Document}} has a <dfn for=document>web bundle list</dfn>, which is a list of [=web bundles=].

# Fetch web bundle # {#fetch-web-bundle-section}
hayatoito marked this conversation as resolved.
Show resolved Hide resolved

<div algorithm>
To <dfn>fetch web bundle</dfn> given [=web bundle=] |web bundle| and [=fetch params=] |fetch params|:
hayatoito marked this conversation as resolved.
Show resolved Hide resolved

1. Assert: |webbundle|'s [=web bundle/state=] is "fetching".

1. Let |request| be |fetch params|'s [=request=].

1. Let |request|'s [=request/url=] is |webbundle|'s [=web bundle/rule=]'s [=bundle rule/source=].

Note: Source URL is resolved on document's base URL.

1. Let |request|'s [=request/destination=] is "webbundle",

1. Let |request|'s [=request/mode=] is "cors",

1. Let |request|'s [=request/credentials mode=] be |web bundle|'s [=web bundle/rule=]'s [=bundle rule/credentials=] if [=bundle rule/credentials=] is non-null. Otherwise "same-origin"
hayatoito marked this conversation as resolved.
Show resolved Hide resolved

1. Append a [=header=], a tuple of ("Accept", "application/webbundle;v=1"), to |request|'s [=request/header list=].
hayatoito marked this conversation as resolved.
Show resolved Hide resolved

Note: Chromium's experimental implementation uses "application/webbundle;v=b2" as a header value.
Once the web bundle format ([[draft-yasskin-wpack-bundled-exchanges]]) goes RFC, Chromium would use "1" as a version number.

1. Let |response| be the result of running <a spec="fetch">HTTP-network-or-cache fetch</a> given |fetch params|.

Note: Chromium's current implementation doesn't allow a *nested bundle*.
A Web bundle is never fetched from other web bundles.

1. If |response|'s [=response/status=] is 200,

1. Let |webbundle|'s [=web bundle/fetched bundle=] be the result of parsing |response|'s body ([[draft-yasskin-wpack-bundled-exchanges]]) and |webbundle|' [=web bundle/state=] be "fetched". If parsing fails, or any other conformance is violated, let [=web bundle/fetched bundle=] be null and [=web bundle/state=] be "failed".

Note: In parsing, Chromium's experimental implementation only accepts "b2" as a web bundle format version number ([[draft-yasskin-wpack-bundled-exchanges]]).
Once the web bundle format goes RFC, Chromium would accept "1" as a web bundle format version number.

1. Otherwise, let |webbundle|' [=web bundle/state=] be "failed".
hayatoito marked this conversation as resolved.
Show resolved Hide resolved

</div>

# HTML monkeypatches # {#html-monkeypatches}

## Script ## {#script}

Note: TODO. This section uses [=fetch web bundle=].

# Fetch monkeypatches # {#fetch-monkeypatches}

## Fetch subresource from web bundle ## {#fetch-subresource-from-web-bundle}

In <a spec="fetch">HTTP-network-or-cache fetch</a>, before

> 8.22. Set httpCache to the result of determining the HTTP cache partition, given|httpRequest|.

add the following steps:

22. Set the |response| to the result of [=fetch from web bundle=], given |httpRequest|.

1. If |response| is [=network error=], return [=network error=].

2. If |response| is non-null, skip the steps 8.22-8.24 and goto the step 9.

Note: That means a subresource from a webbundle never interacts with HttpCache.
We plan to support HttpCache as a feature enhancement in the future.

<div algorithm>
hayatoito marked this conversation as resolved.
Show resolved Hide resolved
To <dfn>fetch from web bundle</dfn> given [=request=] |httpRequest|:

1. For each |web bundle| of [=document=]'s [=document/web bundle list=]:

1. If the result of running [=match url with web bundle=] given |httpRequest|'s [=request/url=] and |web bundle| is true:

1. Let |response| be the result of [=get response from web bundle=] given |httpRequest|'s [=request/url=] and |web bundle|.

2. If |response| is null, return a [=network error=].

Note: This means a browser does not fallback to fetch a subresource from network.

3. Otherwise, return |response|.

2. Return null.

</div>

<div algorithm>
To <dfn>match url with web bundle</dfn> given [=url=] |url| and [=web bundle=] |web bundle|:

1. If |url| doesn't meet a path restriction rule, given |web bundle|'s [=web bundle/rule=]'s [=bundle rule/source=], then return false.

Issue: Clarify path restriction rule in algorithm.


2. If |url| matches any of |web bundle|'s [=web bundle/rule=]'s [=bundle rule/resources=], then return true.

2. If |url|'s prefix matches any of |web bundle|'s [=web bundle/rule=]'s [=bundle rule/scopes=], then return true.

3. Otherwise, return false.

</div>

<div algorithm>
To <dfn>get response from web bundle</dfn> given [=url=] |url| and [=web bundle=] |web bundle|:

1. If |web bundle|'s [=web bundle/state=] is "fetching", await until [=web bundle/state=] becomes "fetched" or "failed" asynchronously.

1. If |web bundle|'s [=web bundle/state=] is "failed", return null.

2. Assert: |web bundle|'s [=web bundle/fetched bundle=] is non-null.

3. Returns [=response=] from |web bundle|'s [=web bundle/fetched bundle=] given |url| ([[draft-yasskin-wpack-bundled-exchanges]]). If a representation of |url| is not found in [=web bundle/fetched bundle=], return null.
</div>

## Navigation ## {#navigation}

Note: TODO