/
protocol.js
86 lines (63 loc) · 2.46 KB
/
protocol.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*-
@module up.protocol
*/
up.migrate.clearCacheFromXHR = function(xhr) {
let value = xhr.getResponseHeader('X-Up-Clear-Cache')
if (value) {
up.migrate.deprecated('X-Up-Clear-Cache', 'X-Up-Expire-Cache')
if (value === 'false') {
return false
} else {
return value
}
}
}
/*-
The server may send this optional response header to control which previously cached responses should be [expired](/caching#expiration) after this response.
The value of this header is a [URL pattern](/url-patterns) matching responses that should be expired.
For example, to expire all responses to URLs starting with `/notes/`:
```http
X-Up-Clear-Cache: /notes/*
```
### Overriding the client-side default
If the server does not send an `X-Up-Clear-Cache` header, Unpoly will [expire the entire cache](/up.network.config#config.expireCache) after a non-GET request.
You may force Unpoly to keep the cache fresh after a non-GET request:
```http
X-Up-Clear-Cache: false
```
@header X-Up-Clear-Cache
@deprecated
Use `X-Up-Expire-Cache` instead.
*/
// X-Up-Title used to carry a window title as a bare string.
// We now require it to be a JSON-encoded string so we can escape high-ASCII characters:
// https://makandracards.com/makandra/536174-http-headers-can-only-transport-us-ascii-characters-safely
up.migrate.titleFromXHR = function(xhr) {
let value = xhr.getResponseHeader('X-Up-Title')
if (value) {
if (value === 'false') {
return false
} else if (value[0] !== '"') {
up.migrate.warn('X-Up-Title must now be a JSON-encoded string')
return value
}
}
}
/*-
This request header contains a timestamp of an existing fragment that is being [reloaded](/up.reload).
The timestamp must be explicitly set by the user as an `[up-time]` attribute on the fragment.
It should indicate the time when the fragment's underlying data was last changed.
See `[up-time]` for a detailed example.
### Format
The time is encoded is the number of seconds elapsed since the [Unix epoch](https://en.wikipedia.org/wiki/Unix_time).
For instance, a modification date of December 23th, 1:40:18 PM UTC would produce the following header:
```http
X-Up-Target: .unread-count
X-Up-Reload-From-Time: 1608730818
```
If no timestamp is known, Unpoly will send a value of zero (`X-Up-Reload-From-Time: 0`).
@header X-Up-Reload-From-Time
@deprecated
Use the standard [`Last-Modified`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Last-Modified) header instead.
@stable
*/