diff --git a/subresource-loading.bs b/subresource-loading.bs index d820be2c..7eb2d6c2 100644 --- a/subresource-loading.bs +++ b/subresource-loading.bs @@ -1,5 +1,5 @@
-Title: Subresource Loading with WebBundles +Title: Subresource Loading with Web Bundles Shortname: web-package-subresource-loading Level: none Status: CG-DRAFT @@ -8,18 +8,31 @@ Repository: WICG/webpackage URL: https://wicg.github.io/webpackage/subresource-loading.html Editor: Hayato Ito, Google Inc. https://google.com/, hayato@google.com 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+
+{ + "draft-ietf-wpack-bundled-responses-latest": { + "href": "https://wpack-wg.github.io/bundled-responses/draft-ietf-wpack-bundled-responses.html", + "title": "Web Bundles" + } +} ++
+spec: fetch; urlPrefix: https://fetch.spec.whatwg.org/# + type: dfn + text: fetch params; url: fetch-params +
+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-
- This specification is under construct. See - #708. -
+Note: This specification is under construction. See +#708. + +# Structures # {#structures} + +A fetched web bundle is a representation of a web bundle format +defined in [[draft-ietf-wpack-bundled-responses-latest]]. + +A bundle rule is a [=struct=] with the following [=struct/items=]: + +- source, a [=URL=]. +- credentials, a [=request/mode=]. +- resources, a list of [=URLs=]. +- scopes, a list of [=URLs=]. + +A web bundle is a [=struct=] with the following [=struct/items=]: + +- fetched bundle, a [=fetched web bundle=] or null. +- rule, a [=bundle rule=]. +- state, an internal state which is "fetching", + "fetched", or "failed". Initially "fetching". + +A {{Document}} has a web bundle list, 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 HTTP-network-or-cache fetch, 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 fetch web bundle 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 HTTP-network-or-cache + fetch 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 fetch from web bundle 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 match url with web bundle +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 get response from web +bundle 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.