Skip to content

Commit

Permalink
Add fetch monkeypatches to subresource-loading spec WICG#708
Browse files Browse the repository at this point in the history
This is a starting point of writing "fetch monkeypatches".

There are still many TODOs remaining, but we can refine iteratively.
  • Loading branch information
hayatoito committed Mar 3, 2022
1 parent 87e5b4a commit c35eaf3
Showing 1 changed file with 155 additions and 7 deletions.
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",
"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=].
- <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}

<div algorithm>
To <dfn>fetch web bundle</dfn> given [=web bundle=] |web bundle| and [=fetch params=] |fetch params|:

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"

1. Append a [=header=], a tuple of ("Accept", "application/webbundle;v=1"), to |request|'s [=request/header list=].

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".

</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>
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

0 comments on commit c35eaf3

Please sign in to comment.