Skip to content

Commit 209783a

Browse files
committed
gateway: clarify SHOULDs for content-location
and some cleanup
1 parent 09d808b commit 209783a

File tree

2 files changed

+56
-28
lines changed

2 files changed

+56
-28
lines changed

src/http-gateways/path-gateway.md

Lines changed: 39 additions & 24 deletions
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,6 +242,16 @@ 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

247257
Only used on CAR requests, same as :ref[dag-scope] from :cite[trustless-gateway].
@@ -486,30 +496,42 @@ To illustrate, `?filename=testтест.pdf` should produce:
486496
not attempt to render raw bytes. CID and `.bin` file extension should be used
487497
if a custom `filename` was not provided with the request.
488498

499+
### `Content-Location` (response header)
500+
501+
Returned when a non-default content format has been negotiated with the
502+
[`Accept` header](#accept-request-header) but `format` was missing from the URL.
503+
504+
The value of this field SHOULD include
505+
the URL of the resource with the `format` query parameter included, so that
506+
generic HTTP caches can store deserialized, CAR, and block responses separately.
507+
508+
:::note
509+
510+
For example, a request to `/ipfs/{cid}` with `Accept: application/vnd.ipld.raw`
511+
SHOULD return a `Content-Location: /ipfs/{cid}?format=raw` header in order for
512+
block response to be cached separately from deserialized one.
513+
514+
:::
515+
489516
### `Content-Length` (response header)
490517

491518
Represents the length of returned HTTP payload.
492519

520+
:::warning
521+
522+
<!-- TODO https://github.com/ipfs/specs/issues/461 -->
523+
493524
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. -->
525+
See [ipfs/specs#461](https://github.com/ipfs/specs/issues/461).
526+
527+
:::
495528

496529
### `Content-Range` (response header)
497530

498531
Returned only when request was a [`Range`](#range-request-header) request.
499532

500533
See Section 14.4 of :cite[rfc9110].
501534

502-
### `Content-Location` (response header)
503-
504-
Returned when a non-default content format has been negotiated with the
505-
[`Accept` header](#accept-request-header). The value of this field SHOULD include
506-
the URL of the resource with the `format` query parameter included, so that
507-
generic HTTP caches can store deserialized, CAR, and block responses separately.
508-
509-
For example, a request to `/ipfs/{cid}` with `Accept: application/vnd.ipld.raw`
510-
SHOULD return a `Content-Location: /ipfs/{cid}?format=raw` header in order for
511-
this request to be able to be successfully cached.
512-
513535
### `Accept-Ranges` (response header)
514536

515537
Optional, returned to explicitly indicate if gateway supports partial HTTP
@@ -524,8 +546,6 @@ deterministic.
524546
Returned only when response status code is [`301` Moved Permanently](#301-moved-permanently).
525547
The value informs the HTTP client about new URL for requested resource.
526548

527-
This header is more widely used in [SUBDOMAIN_GATEWAY.md](./SUBDOMAIN_GATEWAY.md#location-response-header).
528-
529549
#### Use in directory URL normalization
530550

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

564+
#### Use in interop with Subdomain Gateway
565+
566+
See [`Location` section](https://specs.ipfs.tech/http-gateways/subdomain-gateway/#location-response-header) of :cite[subdomain-gateway].
567+
544568
### `X-Ipfs-Path` (response header)
545569

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

581-
<!-- TODO: https://github.com/ipfs/in-web-browsers/issues/194
582-
- `X-Ipfs-DagSize`
583-
- Indicates the total size of the DAG (raw data + IPLD metadata) representing the requested resource.
584-
- For UnixFS this is equivalent to `CumulativeSize` from `ipfs files stat`
585-
- `X-Ipfs-DataSize`
586-
- Indicates the original byte size of the raw data (not impacted by HTTP transfer encoding or compression), without IPFS/IPLD metadata.
587-
- For UnixFS this is equivalent to `Size` from `ipfs files stat` or `ipfs dag stat`
588-
-->
589-
590605
### `X-Content-Type-Options` (response header)
591606

592607
Optional, present in certain response types:

src/http-gateways/trustless-gateway.md

Lines changed: 17 additions & 4 deletions
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,14 @@ 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+
### :dfn[`dag-scope`] (request query parameter)
94101

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

@@ -111,7 +118,7 @@ path segments.
111118

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

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

116123
The optional `entity-bytes=from:to` parameter is available only for CAR
117124
requests.
@@ -203,6 +210,12 @@ If a CAR stream was requested:
203210

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

213+
### `Content-Location` (response header)
214+
215+
Same as in :cite[path-gateway], SHOULD be returned when Trustless Gateway
216+
supports more than a single response format and the `format` query parameter is
217+
missing or does not match well-known format from `Accept` header.
218+
206219
# Block Responses (application/vnd.ipld.raw)
207220

208221
An opaque bytes matching the requested block CID
@@ -217,7 +230,7 @@ A CAR stream for the requested
217230
content type (with optional `order` and `dups` params), path and optional
218231
`dag-scope` and `entity-bytes` URL parameters.
219232

220-
## CAR version
233+
## CAR version (content type parameter)
221234

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

0 commit comments

Comments
 (0)