Skip to content

Commit e4e5754

Browse files
authored
Merge pull request #471 from ipfs/gateway-content-location
gateways: document Content-Location
2 parents 6783eaa + ca46f40 commit e4e5754

File tree

2 files changed

+98
-19
lines changed

2 files changed

+98
-19
lines changed

src/http-gateways/path-gateway.md

+53-15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: >
44
The comprehensive low-level HTTP Gateway enables the integration of IPFS
55
resources into the HTTP stack through /ipfs and /ipns namespaces, supporting
66
both deserialized and verifiable response types.
7-
date: 2023-03-30
7+
date: 2024-04-17
88
maturity: reliable
99
editors:
1010
- name: Marcin Rataj
@@ -242,13 +242,35 @@ These are the equivalents:
242242
When both `Accept` HTTP header and `format` query parameter are present,
243243
`Accept` SHOULD take precedence.
244244

245+
A Client SHOULD include the `format` query parameter in the request URL, in
246+
addition to the `Accept` header. This provides the best interoperability and
247+
ensures consistent HTTP cache behavior across various gateway implementations.
248+
249+
A Gateway SHOULD include the
250+
[`Content-Location`](#content-location-response-header) header in the response when:
251+
- the request contains an `Accept` header specifying a well-known response
252+
format, but the URL does not include the `format` query parameter
253+
- the `format` parameter is present, but does not match the format from `Accept`
254+
245255
### `dag-scope` (request query parameter)
246256

247-
Only used on CAR requests, same as :ref[dag-scope] from :cite[trustless-gateway].
257+
Optional, can be used to limit the scope of verifiable DAG requests such as CAR, same as :ref[dag-scope] from :cite[trustless-gateway].
248258

249259
### `entity-bytes` (request query parameter)
250260

251-
Only used on CAR requests, same as :ref[entity-bytes] from :cite[trustless-gateway].
261+
Optional, can be used to limit the scope of verifiable DAG requests such as CAR, same as :ref[entity-bytes] from :cite[trustless-gateway].
262+
263+
### `car-version` (request query parameter)
264+
265+
Optional, specific to CAR requests, same as :ref[car-version] from :cite[trustless-gateway].
266+
267+
### `car-order` (request query parameter)
268+
269+
Optional, specific to CAR requests, same as :ref[car-order] from :cite[trustless-gateway].
270+
271+
### `car-dups` (request query parameter)
272+
273+
Optional, specific to CAR requests, same as :ref[car-dups] from :cite[trustless-gateway].
252274

253275
# HTTP Response
254276

@@ -486,12 +508,35 @@ To illustrate, `?filename=testтест.pdf` should produce:
486508
not attempt to render raw bytes. CID and `.bin` file extension should be used
487509
if a custom `filename` was not provided with the request.
488510

511+
### `Content-Location` (response header)
512+
513+
Returned when a non-default content format has been negotiated with the
514+
[`Accept` header](#accept-request-header) but `format` was missing from the URL.
515+
516+
The value of this field SHOULD include
517+
the URL of the resource with the `format` query parameter included, so that
518+
generic HTTP caches can store deserialized, CAR, and block responses separately.
519+
520+
:::note
521+
522+
For example, a request to `/ipfs/{cid}` with `Accept: application/vnd.ipld.raw`
523+
SHOULD return a `Content-Location: /ipfs/{cid}?format=raw` header in order for
524+
block response to be cached separately from deserialized one.
525+
526+
:::
527+
489528
### `Content-Length` (response header)
490529

491530
Represents the length of returned HTTP payload.
492531

532+
:::warning
533+
534+
<!-- TODO https://github.com/ipfs/specs/issues/461 -->
535+
493536
NOTE: the value may differ from the real size of requested data if compression or chunked `Transfer-Encoding` are used.
494-
<!-- TODO (https://github.com/ipfs/in-web-browsers/issues/194) IPFS clients looking for UnixFS file size should use value from `X-Ipfs-DataSize` instead. -->
537+
See [ipfs/specs#461](https://github.com/ipfs/specs/issues/461).
538+
539+
:::
495540

496541
### `Content-Range` (response header)
497542

@@ -513,8 +558,6 @@ deterministic.
513558
Returned only when response status code is [`301` Moved Permanently](#301-moved-permanently).
514559
The value informs the HTTP client about new URL for requested resource.
515560

516-
This header is more widely used in [SUBDOMAIN_GATEWAY.md](./SUBDOMAIN_GATEWAY.md#location-response-header).
517-
518561
#### Use in directory URL normalization
519562

520563
Gateway MUST return a redirect when a valid UnixFS directory was requested
@@ -530,6 +573,10 @@ It also ensures the same behavior on path gateways (`https://example.com/ipfs/ci
530573
and origin-isolated HTTP contexts `https://cid.ipfs.dweb.link`
531574
or non-HTTP URLs like `ipfs://cid`, where empty path component is implicit `/`.
532575

576+
#### Use in interop with Subdomain Gateway
577+
578+
See [`Location` section](https://specs.ipfs.tech/http-gateways/subdomain-gateway/#location-response-header) of :cite[subdomain-gateway].
579+
533580
### `X-Ipfs-Path` (response header)
534581

535582
Used for HTTP caching and indicating the IPFS address of the data.
@@ -567,15 +614,6 @@ NOTE: while the first CID will change every time any article is changed,
567614
the last root (responsible for specific article or a subdirectory) may not
568615
change at all, allowing for smarter caching beyond what standard Etag offers.
569616

570-
<!-- TODO: https://github.com/ipfs/in-web-browsers/issues/194
571-
- `X-Ipfs-DagSize`
572-
- Indicates the total size of the DAG (raw data + IPLD metadata) representing the requested resource.
573-
- For UnixFS this is equivalent to `CumulativeSize` from `ipfs files stat`
574-
- `X-Ipfs-DataSize`
575-
- Indicates the original byte size of the raw data (not impacted by HTTP transfer encoding or compression), without IPFS/IPLD metadata.
576-
- For UnixFS this is equivalent to `Size` from `ipfs files stat` or `ipfs dag stat`
577-
-->
578-
579617
### `X-Content-Type-Options` (response header)
580618

581619
Optional, present in certain response types:

src/http-gateways/trustless-gateway.md

+45-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: >
44
The minimal subset of HTTP Gateway response types facilitates data retrieval
55
via CID and ensures integrity verification, all while eliminating the need to
66
trust the gateway itself.
7-
date: 2023-06-20
7+
date: 2024-04-17
88
maturity: reliable
99
editors:
1010
- name: Marcin Rataj
@@ -90,7 +90,18 @@ mode (no deserialized responses) and `Accept` header is missing.
9090

9191
## Request Query Parameters
9292

93-
### :dfn[dag-scope] (request query parameter)
93+
### :dfn[`format`] (request query parameter)
94+
95+
Same as [`format`](https://specs.ipfs.tech/http-gateways/path-gateway/#format-request-query-parameter) in :cite[path-gateway], but with limited number of supported response types:
96+
- `format=raw``application/vnd.ipld.raw`
97+
- `format=car``application/vnd.ipld.car`
98+
- `format=ipns-record``application/vnd.ipfs.ipns-record`
99+
100+
A Client SHOULD include the `format` query parameter in the request URL, in
101+
addition to the `Accept` header. This provides the best interoperability and
102+
ensures consistent HTTP cache behavior across various gateway implementations.
103+
104+
### :dfn[`dag-scope`] (request query parameter)
94105

95106
Optional, `dag-scope=(block|entity|all)` with default value `all`, only available for CAR requests.
96107

@@ -111,7 +122,7 @@ path segments.
111122

112123
When present, returned `Etag` must include unique prefix based on the passed scope type.
113124

114-
### :dfn[entity-bytes] (request query parameter)
125+
### :dfn[`entity-bytes`] (request query parameter)
115126

116127
The optional `entity-bytes=from:to` parameter is available only for CAR
117128
requests.
@@ -183,6 +194,30 @@ returned:
183194
returned to the client, the HTTP status code has already been sent to the
184195
client.
185196

197+
### :dfn[`car-version`] (request query parameter)
198+
199+
Optional, only used on CAR requests.
200+
201+
Serves same purpose as [CAR `version` content type parameter](#car-version-content-type-parameter).
202+
203+
In case both are present in the request, the value from the [`Accept`](#accept-request-header) HTTP Header has priority and a matching [`Content-Location`](#content-location-response-header) SHOULD be returned with the response.
204+
205+
### :dfn[`car-order`] (request query parameter)
206+
207+
Optional, only used on CAR requests.
208+
209+
Serves same purpose as [CAR `order` content type parameter](#car-order-content-type-parameter).
210+
211+
In case both are present in the request, the value from the [`Accept`](#accept-request-header) HTTP Header has priority and a matching [`Content-Location`](#content-location-response-header) SHOULD be returned with the response.
212+
213+
### :dfn[`car-dups`] (request query parameter)
214+
215+
Optional, only used on CAR requests.
216+
217+
Serves same purpose as [CAR `dups` content type parameter](#car-dups-content-type-parameter).
218+
219+
In case both are present in the request, the value from the [`Accept`](#accept-request-header) HTTP Header has priority and a matching [`Content-Location`](#content-location-response-header) SHOULD be returned with the response.
220+
186221
# HTTP Response
187222

188223
Below MUST be implemented **in addition** to "HTTP Response" of :cite[path-gateway].
@@ -203,6 +238,12 @@ If a CAR stream was requested:
203238

204239
MUST be returned and set to `attachment` to ensure requested bytes are not rendered by a web browser.
205240

241+
### `Content-Location` (response header)
242+
243+
Same as in :cite[path-gateway], SHOULD be returned when Trustless Gateway
244+
supports more than a single response format and the `format` query parameter is
245+
missing or does not match well-known format from `Accept` header.
246+
206247
# Block Responses (application/vnd.ipld.raw)
207248

208249
An opaque bytes matching the requested block CID
@@ -217,7 +258,7 @@ A CAR stream for the requested
217258
content type (with optional `order` and `dups` params), path and optional
218259
`dag-scope` and `entity-bytes` URL parameters.
219260

220-
## CAR version
261+
## CAR `version` (content type parameter)
221262

222263
Value returned in
223264
[`CarV1Header.version`](https://ipld.io/specs/transport/car/carv1/#header)

0 commit comments

Comments
 (0)