Skip to content

Commit 6783eaa

Browse files
authored
Merge pull request #466 from ipfs/response-headers
/routing/v1: add missing HTTP cache headers
2 parents 937754a + 814166d commit 6783eaa

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/routing/http-routing-v1.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: >
44
Delegated routing is a mechanism for IPFS implementations to use for offloading
55
content routing, peer routing and naming to another process/server. This specification describes
66
an HTTP API for delegated routing of content, peers, and IPNS.
7-
date: 2023-08-31
7+
date: 2024-03-22
88
maturity: reliable
99
editors:
1010
- name: Gus Eggert
@@ -71,6 +71,17 @@ This API uses a standard version prefix in the path, such as `/v1/...`. If a bac
7171
- `404` (Not Found): must be returned if no matching records are found.
7272
- `422` (Unprocessable Entity): request does not conform to schema or semantic constraints.
7373

74+
#### Response Headers
75+
76+
- `Content-Type`: the content type of this response, which MUST be `application/json` or `application/x-ndjson` (see [streaming](#streaming)).
77+
- `Last-Modified`: an HTTP-date timestamp ([RFC9110, Section 5.6.7](https://www.rfc-editor.org/rfc/rfc9110#section-5.6.7)) of the resolution, allowing HTTP proxies and CDNs to support inexpensive update checks via `If-Modified-Since`
78+
- `Cache-Control: public, max-age={ttl}, public, stale-while-revalidate={max-ttl}, stale-if-error={max-ttl}`: meaningful cache TTL returned with the response.
79+
- The `max-age` SHOULD be shorter for responses whose resolution ended in no results (e.g. 15 seconds),
80+
and longer for responses that have results (e.g. 5 minutes).
81+
- Implementations SHOULD include `max-ttl`, set to the maximum cache window of the underlying routing system.
82+
For example, if Amino DHT results are returned, `stale-while-revalidate` SHOULD be set to `172800` (48h, which at the time of writing this specification, is the provider record expiration window).
83+
- `Vary: Accept`: allows intermediate caches to play nicely with the different possible content types.
84+
7485
#### Response Body
7586

7687
```json
@@ -108,6 +119,17 @@ represented as a CIDv1 encoded with `libp2p-key` codec.
108119
- `404` (Not Found): must be returned if no matching records are found.
109120
- `422` (Unprocessable Entity): request does not conform to schema or semantic constraints.
110121

122+
#### Response Headers
123+
124+
- `Content-Type`: the content type of this response, which MUST be `application/json` or `application/x-ndjson` (see [streaming](#streaming)).
125+
- `Last-Modified`: an HTTP-date timestamp ([RFC9110, Section 5.6.7](https://www.rfc-editor.org/rfc/rfc9110#section-5.6.7)) of the resolution, allowing HTTP proxies and CDNs to support inexpensive update checks via `If-Modified-Since`
126+
- `Cache-Control: public, max-age={ttl}, public, stale-while-revalidate={max-ttl}, stale-if-error={max-ttl}`: meaningful cache TTL returned with the response.
127+
- When present, `ttl` SHOULD be shorter for responses whose resolution ended in no results (e.g. 15 seconds),
128+
and longer for responses that have results (e.g. 5 minutes).
129+
- Implementations SHOULD include `max-ttl`, set to the maximum cache window of the underlying routing system.
130+
For example, if Amino DHT results are returned, `stale-while-revalidate` SHOULD be set to `172800` (48h, which at the time of writing this specification, is the provider record expiration window).
131+
- `Vary: Accept`: allows intermediate caches to play nicely with the different possible content types.
132+
111133
#### Response Body
112134

113135
```json
@@ -148,7 +170,12 @@ Each object in the `Peers` list is a record conforming to the [Peer Schema](#pee
148170
#### Response Headers
149171

150172
- `Etag`: a globally unique opaque string used for HTTP caching. MUST be derived from the protobuf record returned in the body.
151-
- `Cache-Control: max-age={TTL}`: cache TTL returned with :ref[IPNS Record] that has `IpnsEntry.data[TTL] > 0`. When present, SHOULD match the TTL value from the record. When record was not found (HTTP 404) or has no TTL (value is `0`), implementation SHOULD default to `max-age=60`.
173+
- `Cache-Control: public, max-age={ttl}, public, stale-while-revalidate={sig-ttl}, stale-if-error={sig-ttl}`: meaningful cache TTL returned with :ref[IPNS Record]
174+
- The `max-age` value in seconds SHOULD match duration from `IpnsEntry.data[TTL]`, if present and bigger than `0`. Otherwise, implementation SHOULD default to `max-age=60`.
175+
- Implementations SHOULD include `sig-ttl`, set to the remaining number of seconds the returned IPNS Record is valid.
176+
- `Expires:`: an HTTP-date timestamp ([RFC9110, Section 5.6.7](https://www.rfc-editor.org/rfc/rfc9110#section-5.6.7)) when the validity of IPNS Record expires (if `ValidityType=0`, when signature expires)
177+
- `Last-Modified`: an HTTP-date timestamp of when cacheable resolution occured: allows HTTP proxies and CDNs to support inexpensive update checks via `If-Modified-Since`
178+
- `Vary: Accept`: allows intermediate caches to play nicely with the different possible content types.
152179

153180
#### Response Body
154181

0 commit comments

Comments
 (0)