Copyright © 2011 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C liability, trademark and document use rules apply.
This document defines APIs for off-line serving of requests to HTTP resources using static and dynamic responses. It extends the function of application caches defined in HTML5.
Beware. This specification is no longer in active maintenance and the Web Applications Working Group does not intend to maintain it further.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
This document was published by the Web Applications Working Group as a Working Group Note. If you wish to make comments regarding this document, please send them to public-webapps@w3.org (subscribe, archives). All feedback is welcome.
Publication as a Working Group Note does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
This section is non-normative.
The existing cache manifest [HTML5] statically identifies cached
resources to be stored in an application cache. The API introduced
in this document extends the application cache by allowing
applications to programmatically add other resources to the cache
which can then be served by the user agent when that resource is
requested. This API also extends the application cache to enable
applications to programmatically generate responses to requests for
resources that have been added to the application cache. As a result,
the application cache can now be used to satisfy unsafe HTTP methods
such as PUT
and POST
.
Using this application cache extension, applications can obtain locally cached data or data produced locally by JavaScript servers and perform requests on resources that can be served whether or not the user agent is connected to a remote server. Applications can then save and replay locally satisfied requests to the server when it is reconnected, thus enabling responsive and robust Web applications in the presence of low connectivity conditions.
This specification does not require a new programming model for Web applications as application caches can be configured to be transparently pressed into action by the user agent, depending on system conditions. Such applications can seamlessly switch between on-line and off-line operation without needing explicit user action. This also means that existing applications can be used unchanged in many cases once the application cache is configured. Applications only need to be altered to use APIs specified in this document if they require more complex synchronization.
As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.
The key words must, must not, required, should, should not, recommended, may, and optional in this specification are to be interpreted as described in [RFC2119].
This specification defines one class of products:
A user agent must behave as described in this specification in order to be considered conformant.
User agents may implement algorithms given in this specification in any way desired, so long as the end result is indistinguishable from the result that would be obtained by the specification's algorithms.
A conforming user agent must also be a conforming implementation of the IDL fragments of this specification, as described in the Web IDL specification. [WEBIDL]
This specification uses both the terms "conforming user agent(s)" and "user agent(s)" to refer to this product class.
This specification relies on several underlying specifications.
manifest
attribute, and the
Function
and ApplicationCache
interfaces are referenced in this specification and defined by the HTML 5
specification [HTML5].
A conforming user agent must support some version of the HTTP protocol [HTTP11].
In order to protect against attacks, the use of the following headers is prohibited using interfaces defined in this specification.
Accept
Accept-Charset
Accept-Encoding
Accept-Language
Authorization
Cache-Control
Connection
Content-Transfer-Encoding
Cookie
Date
Expect
Host
Keep-Alive
Origin
Range
Referer
Set-Cookie
TE
Trailer
Transfer-Encoding
Upgrade
User-Agent
Via
A conforming user agent must support storage and exchange of cookies as specified by HTTP State Management [COOKIES].
Blob
is referenced by this
specification and defined by the File API specification [FILE-API].
A conforming user agent must define the exception codes
INVALID_STATE_ERR
and
NOT_FOUND_ERR
, and
Event
and DOMException
interface defined in [DOM-LEVEL-3-CORE]
and referenced in this specification.
A managed resource is one whose URI is dynamically captured in an application cache.
A resource is captured when it is dynamically added to an application cache.
A resource is released when it is dynamically removed from an application cache.
A static representation is one that is generated directly by the user agent from an application cache.
A dynamic representation is one that is generated programmatically by using application-supplied logic in an embedded local server.
Transparent off-line data access and manipulation means to locally generate a static or a dynamic response for HTTP requests to captured resources.
Programmable HTTP processing enables applications to identify managed resources to a user agent and to produce static and dynamic representations for responding to requests on these resources.
This section is non-normative.
A user agent processes network requests to managed resources in one of three ways:
The serve policy applies only to resources that do not require interception, whereas the intercept policy can only be used for resources that require interception. Both policies improve availability and responsiveness. However, both may affect data freshness. The review policy can only be used when the user agent is able to communicate with the server. This policy improves data freshness at the cost of reduced responsiveness. User agents may choose freely from among these options, e.g., using information about the system condition, network state or battery power level, or a user preference.
An application can use an application cache to programmatically capture the representation of a resource, i.e., cache an off-line representation in the application cache.
An application captures a resource as part of an atomic cache transaction. Once the resource is captured successfully, the application places the captured representation in to service. This can be performed through a single API call.
var uri = ...
var cache = window.applicationCache;
// cache and immediately take advantage of the new stuff in the cache
cache.immediate(uri);
The user agent is able to then serve this static representation
when an application issues a GET
request for
that resource either through page navigation or an XMLHttpRequest
[XMLHTTPREQUEST].
var req = new XMLHttpRequest();
req.open('GET', uri);
...
req.send();
A dynamic representation is produced by using an embedded local server in conjunction with the application cache. An interceptor processes an HTTP request locally in an embedded local server without changing the network APIs used by applications. Thus even if a host is unreachable, applications can successfully make HTTP requests to a managed resource.
In this example, a local request handler can produce a dynamic response to an application request when the network is not accessible. The response can be prepared using the application cache, for example. The benefit of this technique is that applications don't need to alter their applications to accommodate off-line use cases. Instead, user agents can transparently introduce an application-specific off-line handler to deal with situations when the network is not available.
var uri = ...
var cache = window.applicationCache;
var local = function(request, response) {
response.setStatus(200, 'OK');
response.setResponseText('Hello World');
};
window.navigator.registerOfflineHandler(uri, local);
var req = cache.offline(uri, '', null, ['GET']);
Later when that application issues a GET
request for
the managed resource either through page navigation or an XMLHttpRequest
[XMLHTTPREQUEST], and the user agent is off-line, it invokes the
local
off-line handler which produces a dynamic
response.
var req = new XMLHttpRequest();
req.open('GET', uri);
...
req.send();
Applications can also locally intercept requests that modify data,
e.g., unsafe HTTP requests such as PUT
in an off-line
handler. Requests to resources that are managed in an
application cache can be either:
A user agent can switch between these two behaviors automatically based on system conditions.
For example, an application worker script that wishes to allow off-line updates to uri captures that resource in an application cache.
var uri = ...
var cache = self.applicationCache;
cache.immediate(uri, ['PUT']);
Another application in the same origin could then register an off-line handler for the same uri to serve off-line requests to that resource.
var cache = window.applicationCache;
var intercept = function(request, response) {
if (...) {
// validation fails
response.setStatus(400, 'Bad Request');
response.setResponseText('Request not understood');
return;
}
var type = request.headers['Content-Type'] || 'text/plain';
var req = cache.offline(request.targetURL, request.bodyText, type);
req.onsuccess = function() {
response.setResponseText(request.bodyText);
response.setResponseHeader('Content-Type', type);
response.setStatus(200, 'OK');
}
};
var review = function(request, response) {
var req = cache.offline(request.targetURL, response.bodyText, response.headers['Content-Type']);
};
window.navigator.registerOfflineHandler(uri, intercept, review);
When the application makes a PUT
request to
uri and the user agent is off-line,
the user agent asks the intercept function to
process the request and respond to it. If the user agent is online
when the request arrives, then it sends the request to
a host and asks the review function to process the
response received from it.
var req = new XMLHttpRequest();
req.open('PUT', uri);
...
req.send(...);
If this application makes a GET
request to
uri, then its cached static representation is
returned as the response regardless of whether the user agent is off-line.
var req = new XMLHttpRequest();
req.open('GET', uri);
...
req.send();
This section is non-normative.
An application updates the managed resources of an application cache. During this update, the user agent will add or remove the representations of managed resources to and from the application cache.
As this is going on, a number of events get fired to keep the script updated as to the state of the cache transaction, so that the user can be notified appropriately. The events are as follows:
Event name | Occasion | Next events |
---|---|---|
captured |
The user agent has finished fetching and storing the representation of a managed resource. |
captured ,
released ,
ready
|
released |
The user agent has released a managed resource and can no longer serve off-line requests to it. |
captured ,
released ,
ready
|
ready |
The user agent has finished capturing and releasing the requested resources and does not have any pending requests in this cache transaction. | Last event in sequence. |
This specification adds two new kinds of entries for application cache to the various kinds defined in [HTML5]:
Each application cache has a dynamic completeness flag, which is either incomplete or complete. Each application cache whose dynamic completeness flag is complete has a version. No two application caches in an application cache group may have the same version. A newer application cache has a larger version.
Each application cache group has a dynamic update status, which is one of the following: idle or updating.
Application scripts identify the resources managed by an application cache during a cache transaction, when applications may either capture or release its resources.
Each cache transaction has an application cache group and an application cache.
A cache transaction can be marked as off-line transaction.
Each cache transaction has a commit status, which can be either of pending, committed, or aborted.
When a cache transaction is started, the user agent must run the steps to create a cache transaction. When a resource is added to a transaction's list of captured resources, the user agent must run the steps to add a resource to be captured. When a resource is added to a transaction's list of released resources, the user agent must run the steps to add a resource to be released. When the transaction is finished, the user agent must run either the steps to commit a cache transaction or the steps to abort a cache transaction.
When the user agent is required to create a cache transaction given an application cache group and an off-line flag, the user agent must run the following steps:
When the user agent is required to add a resource to be captured, given the URI of the resource to capture, a cache transaction, optionally a list of dynamic methods, optionally content to serve as the static representation of that resource, and optionally content type for that representation, the user agent must perform the following steps:
Document
objectWorkerGlobalScope
object<scheme>
component than the base URI (compared in an ASCII case-insensitive
manner), then set an error and abort these steps.
<fragment>
component of the resulting
absolute URI, if it has one.
GET
, then skip the
remaining sub-steps and store in cache a
managed resource comprising the resulting absolute
URI and the list of
dynamic methods passed to these steps.
If the resource in question is already being fetched for other reasons, then the existing download process can sometimes be used for the purposes of this step.
Redirects are fatal because they are either indicative of a network problem (e.g. a captive portal); or would allow resources to be added to the cache under URIs that differ from any URI that the networking model will allow access to, leaving orphan entries; or would allow resources to be stored under URIs different than their true URIs. All of these situations are bad.
GET
, then skip the
remaining sub-steps and store in cache a
managed resource comprising the resulting absolute
URI and the list of
dynamic methods passed to these steps.
text/plain
.
captured
, which
does not bubble, is not cancelable, and which uses the
CacheEvent
interface.
The capture failure steps are performed with a status code as follows:
404
or 410
or equivalent, thenAttempts to fetch resources as part of the steps to add a resource to be captured may be done with cache-defeating semantics, to avoid problems with stale or inconsistent intermediary caches.
When the user agent is required to add a resource to be released, given the URI of the resource to release, and a cache transaction, the user agent must perform the following steps:
Document
objectWorkerGlobalScope
object<scheme>
component than the base URI (compared in an ASCII case-insensitive
manner), then set an error and abort these steps.
<fragment>
component of the resulting
absolute URI, if it has one.
released
, which
does not bubble, is not cancelable, and which uses the
CacheEvent
interface.
When the user agent is required to commit a cache transaction, given a cache transaction, it means that the user agent must run the following steps:
ready
,
which does not bubble, is not cancelable, and which uses the
Event
interface.
When the user agent is required to abort a cache transaction, given a cache transaction, it means that the user agent must run the following steps:
Here's how a shared worker opens an application cache group.
var cache = self.applicationCache;
Here's how a window opens an application cache group.
var cache = window.applicationCache;
[Supplemental]
interface CacheUtil {
attribute ApplicationCache2Request
applicationCache;
};
applicationCache
of type ApplicationCache2Request
(In a window.) Returns the ApplicationCache2Request
object that applies to the active document
of that Window
.
(In a shared worker.) Returns the ApplicationCache2Request
object that applies to the current shared worker.
Window implements CacheUtil
;
WorkerGlobalScope implements CacheUtil
;
All instances of the WorkerGlobalScope
type are defined to also implement the CacheUtil
interface.
Events are fired during asynchronous access as managed resources are accessed and manipulated. As requests are made for managed resources, the user agent processes them and saves or retrieves data from the network or storage, and when the required data is available, it alerts the application through the firing of events. The events are as follows:
Event name | Dispatched when... |
---|---|
success |
The application cache request has been completed and its results are available. |
error |
There was an error performing the application cache request. |
interface AppCacheRequest {
void abort ();
const unsigned short INITIAL = 0;
const unsigned short LOADING = 1;
const unsigned short DONE = 2;
readonly attribute unsigned short readyState;
readonly attribute any error;
readonly attribute any result;
attribute Function onsuccess;
attribute Function onerror;
};
error
of type any, readonlyonerror
of type Functionerror
eventonsuccess
of type Functionsuccess
eventreadyState
of type unsigned short, readonlyresult
of type any, readonlyabort
readyState
to
INITIAL
. No
result
or
error
is
set.void
DONE
of type unsigned shortresult
or
error
attribute.INITIAL
of type unsigned shortLOADING
of type unsigned shortApplicationCache
interface
Additional metadata is available about an
application cache through the
ApplicationCache2
.
interface ApplicationCache2 : ApplicationCache {
readonly attribute unsigned long version;
readonly attribute unsigned long long size;
readonly attribute long long lastRefresh;
readonly attribute unsigned long pendingUpdates;
readonly attribute DOMString outbox;
};
lastRefresh
of type long long, readonlyoutbox
of type DOMString, readonlypendingUpdates
of type unsigned long, readonlysize
of type unsigned long long, readonlyversion
of type unsigned long, readonlyinterface ApplicationCache2Request : ApplicationCache2
{
AppCacheRequest
setOutbox (in DOMString uri);
AppCacheRequest
immediate (in DOMString uri, in optional DOMString dynamicMethods);
AppCacheRequest
offline (in DOMString uri, in DOMString body, in optional DOMString contentType, in optional DOMString dynamicMethods);
AppCacheRequest
transaction (in optional boolean restart);
AppCacheRequest
offlineTransaction ();
CacheCursorRequest
openModifiedItemCursor (in long version) raises (DOMException);
};
immediate
AppCacheRequest
object called
result and asynchronously performs the following steps:
error
to be the error of the previous step.
error
, which
does not bubble, is not cancelable, and which uses the
Event
interface.
error
to be the error of the previous step.
error
, which
does not bubble, is not cancelable, and which uses the
Event
interface.
success
, which
does not bubble, is not cancelable, and which uses the
Event
interface.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
uri | DOMString | ✘ | ✘ | identifying the resource to capture |
dynamicMethods | DOMString | ✘ | ✔ | The dynamic methods that are applicable to the identified resource. This parameter is a comma separated list of protocol methods that can be intercepted for local processing. An empty string is allowed for this parameter. |
AppCacheRequest
offline
AppCacheRequest
object called
result and asynchronously performs the following steps:
error
to be the error of the previous step.
error
, which
does not bubble, is not cancelable, and which uses the
Event
interface.
error
to be the error of the previous step.
error
, which
does not bubble, is not cancelable, and which uses the
Event
interface.
success
, which
does not bubble, is not cancelable, and which uses the
Event
interface.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
uri | DOMString | ✘ | ✘ | identifying the resource to capture |
body | DOMString | ✘ | ✘ | entity body for the resource |
contentType | DOMString | ✘ | ✔ | The MIME type of the entity body |
dynamicMethods | DOMString | ✘ | ✔ | The dynamic methods that are applicable to the identified resource. This parameter is a comma separated list of protocol methods that can be intercepted for local processing. An empty string is allowed for this parameter. |
AppCacheRequest
offlineTransaction
AppCacheRequest
object called
result and asynchronously performs the following steps:
error
to be the error of the previous step.
error
, which
does not bubble, is not cancelable, and which uses the
Event
interface
OfflineTransactionRequest
object for
transaction.
result
to be txn.
success
, which
does not bubble, is not cancelable, and which uses the
Event
interface.
AppCacheRequest
openModifiedItemCursor
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
version | long | ✘ | ✘ | Version of this
application cache since which modifications are sought.
A value 0 indicates that every modification since
the first cache transaction of this
application cache is sought. |
Exception | Description |
---|---|
DOMException |
The method must raise an
INVALID_STATE_ERR if
the version passed to these steps is not less than the
version of this application cache.
|
CacheCursorRequest
setOutbox
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
uri | DOMString | ✘ | ✘ | identifying the resource to use as the URL for processing items in the outbox of the application using this application cache |
AppCacheRequest
transaction
AppCacheRequest
object called
result and asynchronously performs the following steps:
error
to be the error of the previous step.
error
, which
does not bubble, is not cancelable, and which uses the
Event
interface.
OnlineTransactionRequest
object for
transaction.
result
to be txn.
success
, which
does not bubble, is not cancelable, and which uses the
Event
interface.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
restart | boolean | ✘ | ✔ | This defaults to false. This flag specifies whether to continue a previously abandoned cache transaction. |
AppCacheRequest
When the user agent is required to create a cache cursor,
given the application cache and the
low watermark version, the user agent must return a new
CacheCursorRequest
object, called result
and asynchronously perform the following steps:
result
to the item at cursor's current position in
item list.
success
, which
does not bubble, is not cancelable, and which uses the
Event
interface.
interface CacheCursorRequest : AppCacheRequest
{
void continue ();
};
continue
error
to be 0
.
error
, which
does not bubble, is not cancelable, and which uses the
Event
interface.
result
to the item at cursor's current position in
item list.
success
, which
does not bubble, is not cancelable, and which uses the
Event
interface
void
interface CacheTransactionRequest {
attribute Function oncaptured;
attribute Function onreleased;
attribute Function onready;
void resetPendingUpdates ();
void incrementPendingUpdates ();
void decrementPendingUpdates ();
AppCacheRequest
getItem (in DOMString uri);
AppCacheRequest
release (in DOMString uri);
AppCacheRequest
abort ();
AppCacheRequest
commit ();
};
oncaptured
of type Functioncaptured
eventonready
of type Functionready
eventonreleased
of type Functionreleased
eventabort
AppCacheRequest
object called result and
asynchronously perform the following steps:
error
to be the error set in the above steps.
error
, which
does not bubble, is not cancelable, and which uses the
Event
interface.
success
, which
does not bubble, is not cancelable, and which uses the
Event
interface.
AppCacheRequest
commit
AppCacheRequest
object called result and
asynchronously perform the following steps:
error
to be the error set in the above steps.
error
, which
does not bubble, is not cancelable, and which uses the
Event
interface.
success
, which
does not bubble, is not cancelable, and which uses the
Event
interface.
AppCacheRequest
decrementPendingUpdates
1
void
getItem
AppCacheRequest
object called result and
asynchronously perform the following steps:
error
to be NOT_FOUND_ERR
.
error
, which
does not bubble, is not cancelable, and which uses the
Event
interface.
CacheItem
object with the associated item.
result
to object.
success
, which
does not bubble, is not cancelable, and which uses the
Event
interface.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
uri | DOMString | ✘ | ✘ | identifying the resource |
AppCacheRequest
incrementPendingUpdates
1
void
release
AppCacheRequest
object called result and
asynchronously perform the following steps:
error
to be the error set in the above steps.
error
, which
does not bubble, is not cancelable, and which uses the
Event
interface.
success
, which
does not bubble, is not cancelable, and which uses the
Event
interface.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
uri | DOMString | ✘ | ✘ | identifying the resource to release |
AppCacheRequest
resetPendingUpdates
0
void
interface OnlineTransactionRequest : CacheTransactionRequest
{
AppCacheRequest
capture (in DOMString uri, in optional DOMString dynamicMethods);
};
capture
AppCacheRequest
object called result and
asynchronously perform the following steps:
error
to be the error of the previous step.
error
, which
does not bubble, is not cancelable, and which uses the
Event
interface.
success
, which
does not bubble, is not cancelable, and which uses the
Event
interface.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
uri | DOMString | ✘ | ✘ | identifying the resource to capture |
dynamicMethods | DOMString | ✘ | ✔ | The dynamic methods that are applicable to the identified resource. This parameter is a comma separated list of protocol methods that can be intercepted for local processing. An empty string is allowed for this parameter. |
AppCacheRequest
interface OfflineTransactionRequest : CacheTransactionRequest
{
AppCacheRequest
capture (in DOMString uri, in DOMString body, in optional DOMString contentType, in optional DOMString dynamicMethods);
};
capture
AppCacheRequest
object called result and
asynchronously perform the following steps:
error
to be the error of the previous step.
error
, which
does not bubble, is not cancelable, and which uses the
Event
interface.
success
, which
does not bubble, is not cancelable, and which uses the
Event
interface.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
uri | DOMString | ✘ | ✘ | identifying the resource to capture |
body | DOMString | ✘ | ✘ | entity body for the resource |
contentType | DOMString | ✘ | ✔ | The MIME type of the entity body |
dynamicMethods | DOMString | ✘ | ✔ | The dynamic methods that are applicable to the identified resource. This parameter is a comma separated list of protocol methods that can be intercepted for local processing. An empty string is allowed for this parameter. |
AppCacheRequest
interface CacheItem {
const unsigned short UNCACHED = 0;
const unsigned short FETCHING = 1;
const unsigned short CACHED = 2;
const unsigned short GONE = 3;
readonly attribute unsigned short readyState;
readonly attribute Blob body;
readonly attribute DOMStringList dynamicMethods;
readonly attribute any headers;
};
body
of type Blob, readonlyBlob
object, of the managed
resource associated with this CacheItem
object.
dynamicMethods
of type DOMStringList, readonlyCacheItem
object.
headers
of type any, readonlyCacheItem
object. In the ECMAScript
binding, this must be Object
. Each header must have
one property (or dictionary
entry), with those properties enumerating in the order that the headers
were recorded in the managed resource. Each property must
have the name of the header and its value as recorded in the
managed resource.
readyState
of type unsigned short, readonlyCACHED
of type unsigned shortCacheItem
object is associated with a
managed resource which has been cached.
FETCHING
of type unsigned shortCacheItem
object is associated with a
managed resource which is currently being fetched.
There is no value available in
body
or headers
.
GONE
of type unsigned shortCacheItem
object is associated with a
managed resource which has been released. There is no
value available in
body
,
headers
, or
dynamicMethods
.
UNCACHED
of type unsigned shortCacheItem
object is associated with a
managed resource
which has been added for capturing but has not yet been cached.
There is no value available in body
or headers
.
CacheEvent
InterfaceThe task source for this task is the networking task source.
interface CacheEvent : Event {
readonly attribute DOMString uri;
void initCacheEvent (in optional DOMString uri);
void initCacheEventNS (in DOMString namespaceURI, in optional DOMString uri);
};
initCacheEvent
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
uri | DOMString | ✘ | ✔ |
void
initCacheEventNS
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
namespaceURI | DOMString | ✘ | ✘ | |
uri | DOMString | ✘ | ✔ |
void
The following are the event handlers (and their corresponding
event handler event types) that must be supported, as IDL
attributes, by objects implementing the
CacheTransaction
interface and
CacheTransactionRequest
interface:
Event handler | Event handler event type |
---|---|
onready |
ready |
oncaptured |
captured |
onreleased |
released |
An embedded local server is an application script that generates dynamic responses to resource requests without making those requests to the origin server.
An embedded local server consists of an interceptor function and zero or one reviewer function.
An embedded local server serves requests to resources in its interception namespace.
A cache host can be associated with zero or more embedded local servers.
An resource request issued in a cache host can be an interceptible request if the resource is in the interception namespace of an embedded local server registered in the browsing context of the cache host and the resource is a dynamic entry in the application cache group associated with the cache host and the request method is identified as one of the dynamic entry's dynamic methods .
If an embedded local server can intercept a resource request, then it is called a candidate local server for that request.
Multiple embedded local servers can be the candidate local server for a given resource request. If a user agent is to select an embedded local server from a list of candidate local servers that can produce a dynamic representation of the requested resource, then the user agent must use the embedded local server that has the most specific interception namespace.
This method allows applications to register possible handlers
for particular URI namespaces. Upon being invoked, this method
should create a new embedded local server called
server with its interceptor
function set to intercept handler and its
reviewer function set to review handler
and add server to the cache host, which is
the active document of the browsing context of the
window
containing this Navigator
object.
If a handler already exists for the given namespace,
the existing embedded local server is replaced with the
one created in this call.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
namespace | DOMString | ✘ | ✘ | identifying the interception namespace for this embedded local server |
intercept |
| ✘ | ✘ | the interceptor function of this embedded local server |
review |
| ✘ | ✔ | the reviewer function of this embedded local server |
void
window
containing this Navigator
object.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
namespace | DOMString | ✘ | ✘ | identifying the interception namespace for this embedded local server |
Exception | Description |
---|---|
DOMException |
The method must raise an
NOT_FOUND_ERR if
the version passed to these steps is not less than the
version of this application cache.
|
void
Navigator implements NavigatorLocalServer
;
All instances of the Navigator
type are defined to also implement the NavigatorLocalServer
interface.
[Callback=FunctionOnly, NoInterfaceObject]
interface InterceptHandler {
void callback (in HttpRequest
request, in MutableHttpResponse
response);
};
callback
The user agent must invoke the InterceptHandler
,
with an HttpRequest
object request based on the application's resource request and an
MutableHttpResponse
object response. If the
delay()
method is invoked on response,
then when the
send()
method is invoked on response, the
user agent must respond to request with the headers, body, and
status specified in response.
If the
delay()
method is not invoked on response
in this callback, then the user agent must respond to request
with the headers, body, and status, specified in response
when this function exits.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
request |
| ✘ | ✘ | |
response |
| ✘ | ✘ |
void
[Callback=FunctionOnly, NoInterfaceObject]
interface ReviewHandler {
void callback (in HttpRequest
request, in HttpResponse
response);
};
callback
The user agent must invoke the ReviewHandler
,
with an HttpRequest
object request based on the application's resource request and an
HttpResponse
object response based on the host's response to that request.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
request |
| ✘ | ✘ | |
response |
| ✘ | ✘ |
void
interface HttpRequest {
readonly attribute DOMString method;
readonly attribute DOMString target;
readonly attribute DOMString bodyText;
readonly attribute any headers;
};
bodyText
of type DOMString, readonlycharset
parameter of the Content-Type
header or null
if there was no charset
parameter or if the header could not be parsed properly or was
omitted.
Content-Type
header contains without any parameters or null
if
the header could not be parsed properly or was omitted.
null
and mime
is text/xml
,
application/xml
, or ends in +xml
use the rules set forth in the XML specifications to determine
the character encoding. Let charset be the
determined character encoding.
null
and mime is
application/json
follow the rules set forth in the
[RFC4627] specification to determine the character encoding.
Let charset be the determined character encoding.
null
and mime is
text/html
follow the rules set forth in the [HTML5]
specification to determine the character encoding. Let
charset be the determined character encoding.
null
, then let
charset be UTF-8
.
headers
of type any, readonlyHttpRequest
object.
In the JavaScript binding, this must be
Object
. Each header must have one property (or dictionary
entry), with those properties enumerating in the order that the headers
were present in the request. Each property must have the name of the
header and its value as present in the request.
method
of type DOMString, readonlyHttpRequest
object.
target
of type DOMString, readonlyHttpRequest
object.
interface MutableHttpResponse {
void setStatus (in unsigned short code, in DOMString message);
void setResponseText (in DOMString text);
void setResponseHeader (in DOMString name, in DOMString value);
void delay ();
void send ();
};
delay
InterceptHandler
would need to explicitly call
send()
in order to mark the response as ready for being returned to the
application.
void
send
MutableHttpResponse
object. No further changes must be allowed to it.
void
setResponseHeader
MutableHttpResponse
object. If a value is already associated with this header, then
this method must append value to it.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
name | DOMString | ✘ | ✘ | |
value | DOMString | ✘ | ✘ |
void
setResponseText
MutableHttpResponse
object, replacing any previous value.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
text | DOMString | ✘ | ✘ |
void
setStatus
MutableHttpResponse
object, replacing any previous values for both.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
code | unsigned short | ✘ | ✘ | |
message | DOMString | ✘ | ✘ |
void
interface HttpResponse {
readonly attribute unsigned short statusCode;
readonly attribute DOMString statusMessage;
readonly attribute DOMString bodyText;
readonly attribute any headers;
};
bodyText
of type DOMString, readonlycharset
parameter of the Content-Type
header or null
if there was no charset
parameter or if the header could not be parsed properly or was
omitted.
Content-Type
header contains without any parameters or null
if
the header could not be parsed properly or was omitted.
null
and mime
is text/xml
,
application/xml
, or ends in +xml
use the rules set forth in the XML specifications to determine
the character encoding. Let charset be the
determined character encoding.
null
and mime is
application/json
follow the rules set forth in the
[RFC4627] specification to determine the character encoding.
Let charset be the determined character encoding.
null
and mime is
text/html
follow the rules set forth in the [HTML5]
specification to determine the character encoding. Let
charset be the determined character encoding.
null
, then let
charset be UTF-8
.
headers
of type any, readonlyHttpResponse
object.
In the JavaScript binding, this must be
Object
. Each header must have one property (or dictionary
entry), with those properties enumerating in the order that the headers
were present in the response. Each property must have the name of the
header and its value as present in the response.
statusCode
of type unsigned short, readonlyHttpResponse
object.
statusMessage
of type DOMString, readonlyHttpResponse
object.
When a cache host is associated with an application cache whose dynamic completeness flag is complete, any and all loads for resources related to that cache host other than those for child browsing contexts must go through the following steps prior to the the networking model for application caches defined in [HTML5].
Cache-Control
with the value no-cache
, then fetch the resource
normally, and abort these steps.
GET
mechanism
and resource is not defined in cache with a
dynamic GET
method,
then get the entity for resource from cache
(instead of fetching it), and abort these steps.
HEAD
mechanism
and resource is not defined in cache with a
dynamic HEAD
method,
then get the entity headers for resource from cache
(instead of fetching it), and abort these steps.
Apart from requirements affecting security made throughout this specification implementations may, at their discretion, not expose certain headers, such as HttpOnly cookies.