Skip to content

Commit

Permalink
Merge pull request #715 from hayatoito/subresource-loading-spec-fetch
Browse files Browse the repository at this point in the history
Add fetch monkeypatches to subresource-loading spec #708
  • Loading branch information
hayatoito authored Mar 7, 2022
2 parents bb47d16 + d9d8e08 commit aef4300
Showing 1 changed file with 173 additions and 8 deletions.
181 changes: 173 additions & 8 deletions subresource-loading.bs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<pre class="metadata">
Title: Subresource Loading with WebBundles
Title: Subresource Loading with Web Bundles
Shortname: web-package-subresource-loading
Level: none
Status: CG-DRAFT
Expand All @@ -8,18 +8,31 @@ 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
Indent: 2
Markup Shorthands: markdown yes, css no
Assume Explicit For: yes
</pre>
<pre class='biblio'>
{
"draft-ietf-wpack-bundled-responses-latest": {
"href": "https://wpack-wg.github.io/bundled-responses/draft-ietf-wpack-bundled-responses.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 +44,159 @@ 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 construction. 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-ietf-wpack-bundled-responses-latest]].

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

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

# HTML monkeypatches # {#html-monkeypatches}

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

# Fetch monkeypatches # {#fetch-monkeypatches}

## Monkeypatch HTTP-network-or-cache fetch ## {#monkeypatch-http-network-or-cache-fetch}

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.

# Algorithms # {#algorithms}

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

To <dfn id="concept-fetch-web-bundle">fetch web bundle</dfn> given [=web
bundle=] |web bundle| and [=fetch params=] |fetch params|:

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

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

1. Set |request|'s [=request/url=] to |web bundle|'s [=web bundle/rule=]'s
[=bundle rule/source=].

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

1. Set |request|'s [=request/destination=] to "webbundle",

1. Set |request|'s [=request/mode=] to "cors",

1. Set |request|'s [=request/credentials mode=] to |web bundle|'s [=web
bundle/rule=]'s [=bundle rule/credentials=].

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

Note: The final [[draft-ietf-wpack-bundled-responses-latest]] will use a
version of `1`, but this specification tracks what’s actually implemented in
browsers, which still uses draft versions.

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. Set |web bundle|'s [=web bundle/fetched bundle=] to the result of parsing
|response|'s body ([[draft-ietf-wpack-bundled-responses-latest]]) and |web
bundle|'s [=web bundle/state=] be "fetched". If parsing fails, or any
other conformance is violated, set [=web bundle/fetched bundle=] to null
and [=web bundle/state=] to "failed".

Note: In parsing, Chromium's experimental implementation only accepts "b2"
as a web bundle format version number
([[draft-ietf-wpack-bundled-responses-latest]]).

1. Otherwise, set |web bundle|'s [=web bundle/state=] to "failed".

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

To <dfn id="concept-fetch-from-web-bundle">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.

## Match url with web bundle ## {#match-url-with-web-bundle}

To <dfn id="concept-match-url-with-web-bundle">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.

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

4. Otherwise, return false.

## Get response from web bundle ## {#get-response-from-web-bundle}

To <dfn id="concept-get-response-from-web-bundle">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.

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

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

4. Returns [=response=] from |web bundle|'s [=web bundle/fetched bundle=] given
|url| ([[draft-ietf-wpack-bundled-responses-latest]]). If a representation of
|url| is not found in [=web bundle/fetched bundle=], return null.

0 comments on commit aef4300

Please sign in to comment.