You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Best practices for HTTP caching](#best-practices-for-http-caching)
84
86
-[Denylists](#denylists)
@@ -182,10 +184,10 @@ For example:
182
184
-[application/vnd.ipld.raw](https://www.iana.org/assignments/media-types/application/vnd.ipld.raw) – disables [IPLD codec deserialization](https://ipld.io/docs/codecs/), requests a verifiable raw [block](https://docs.ipfs.io/concepts/glossary/#block) to be returned
183
185
-[application/vnd.ipld.car](https://www.iana.org/assignments/media-types/application/vnd.ipld.car) – disables [IPLD codec deserialization](https://ipld.io/docs/codecs/), requests a verifiable [CAR](https://docs.ipfs.io/concepts/glossary/#car) stream to be returned
184
186
-[application/x-tar](https://en.wikipedia.org/wiki/Tar_(computing)) – returns UnixFS tree (files and directories) as a [TAR](https://en.wikipedia.org/wiki/Tar_(computing)) stream. Returned tree starts at a root item which name is the same as the requested CID. Produces 400 Bad Request for content that is not UnixFS.
- application/vnd.ipld.dag-json OR application/json – requests IPLD Data Model representation serialized into [DAG-JSON format](https://ipld.io/docs/codecs/known/dag-json/)
187
-
- application/vnd.ipld.dag-cbor OR application/cbor - requests IPLD Data Model representation serialized into [DAG-CBOR format](https://ipld.io/docs/codecs/known/dag-cbor/)
188
-
-->
187
+
-[application/vnd.ipld.dag-json](https://www.iana.org/assignments/media-types/application/vnd.ipld.dag-json) – requests [IPLD Data Model](https://ipld.io/docs/data-model/) representation serialized into [DAG-JSON format](https://ipld.io/docs/codecs/known/dag-json/). If the requested CID already has `dag-json` (0x0129) codec, data is validated as DAG-JSON before being returned as-is. Invalid DAG-JSON produces HTTP Error 500.
188
+
-[application/vnd.ipld.dag-cbor](https://www.iana.org/assignments/media-types/application/vnd.ipld.dag-cbor) – requests [IPLD Data Model](https://ipld.io/docs/data-model/) representation serialized into [DAG-CBOR format](https://ipld.io/docs/codecs/known/dag-cbor/). If the requested CID already has `dag-cbor` (0x71) codec, data is validated as DAG-CBOR before being returned as-is. Invalid DAG-CBON produces HTTP Error 500.
189
+
-[application/json](https://www.iana.org/assignments/media-types/application/json) – same as `application/vnd.ipld.dag-json`, unless the CID's codec already is `json` (0x0200). Then, the raw JSON block can be returned as-is without any conversion.
190
+
-[application/cbor](https://www.iana.org/assignments/media-types/application/cbor) – same as `application/vnd.ipld.dag-cbor`, unless the CID's codec already is `cbor` (0x51). Then, the raw CBOR block can be returned as-is without any conversion.
189
191
190
192
### `Range` (request header)
191
193
@@ -246,11 +248,14 @@ parameter, if present)
246
248
247
249
Optional, `format=<format>` can be used to request specific response format.
248
250
249
-
This is a URL-friendly alternative to sending
250
-
`Accept: application/vnd.ipld.<format>` header, see [`Accept`](#accept-request-header)
251
-
for more details.
252
-
253
-
In case of `Accept: application/x-tar`, the `?format=` equivalent is `tar`.
251
+
This is a URL-friendly alternative to sending an [`Accept`](#accept-request-header) header. These are the equivalents:
<!-- TODO Planned: https://github.com/ipfs/go-ipfs/issues/8769
256
261
- `selector=<cid>` can be used for passing a CID with [IPLD selector](https://ipld.io/specs/selectors)
@@ -584,24 +589,38 @@ A good practice is to always return it with HTTP error [status codes](#response-
584
589
585
590
## Response Payload
586
591
587
-
Data sent with HTTP response depends on the type of requested IPFS resource:
592
+
Data sent with HTTP response depends on the type of the requested IPFS resource, and the requested response type.
593
+
594
+
By default, implicit deserialized response type is based on `Accept` header and the codec of the resolved CID:
588
595
589
-
- UnixFS (implicit default)
590
-
- File
591
-
- Bytes representing file contents
596
+
- UnixFS, either `dag-pb` (0x70) or `raw` (0x55)
597
+
- File or `raw` block
598
+
- Bytes representing file/block contents
599
+
- When `Range` is present, only the requested byte range is returned.
592
600
- Directory
593
601
- Generated HTML with directory index (see [additional notes here](#generated-html-with-directory-index))
594
-
- When `index.html` is present, gateway can skip generating directory index and return it instead
595
-
- Raw block
596
-
- Opaque bytes, see [application/vnd.ipld.raw](https://www.iana.org/assignments/media-types/application/vnd.ipld.raw)
597
-
- CAR
598
-
- Arbitrary DAG as a verifiable CAR file or a stream, see [application/vnd.ipld.car](https://www.iana.org/assignments/media-types/application/vnd.ipld.car)
599
-
- TAR
600
-
- Deserialized UnixFS files and directories as a TAR file or a stream, see [application/x-tar](https://en.wikipedia.org/wiki/Tar_(computing))
- See [https://github.com/ipfs/go-ipfs/issues/8823](https://github.com/ipfs/go-ipfs/issues/8823)
604
-
-->
602
+
- When `index.html` is present, gateway MUST skip generating directory index and return content from `index.html` instead.
603
+
- JSON (0x0200)
604
+
- Bytes representing a JSON file, see [application/json](https://www.iana.org/assignments/media-types/application/json).
605
+
- Works exactly the same as `raw`, but returned `Content-Type` is `application/json`
606
+
- CBOR (0x51)
607
+
- Bytes representing a CBOR file, see [application/cbor](https://www.iana.org/assignments/media-types/application/cbor)
608
+
- Works exactly the same as `raw`, but returned `Content-Type` is `application/cbor`
609
+
- DAG-JSON (0x0129)
610
+
- If the `Accept` header includes `text/html`, implementation should return a generated HTML with options to download DAG-JSON as-is, or converted to DAG-CBOR.
611
+
- Otherwise, response works exactly the same as `raw` block, but returned `Content-Type` is [application/vnd.ipld.dag-json](https://www.iana.org/assignments/media-types/application/vnd.ipld.dag-json)
612
+
- DAG-CBOR (0x71)
613
+
- If the `Accept` header includes `text/html`: implementation should return a generated HTML with options to download DAG-CBOR as-is, or converted to DAG-JSON.
614
+
- Otherwise, response works exactly the same as `raw` block, but returned `Content-Type` is [application/vnd.ipld.dag-cbor](https://www.iana.org/assignments/media-types/application/vnd.ipld.dag-cbor)
615
+
616
+
The following response types require an explicit opt-in, can only be requested with [`format`](#format-request-query-parameter) query parameter or [`Accept`](#accept-request-header) header:
617
+
618
+
- Raw Block (`?format=raw`)
619
+
- Opaque bytes, see [application/vnd.ipld.raw](https://www.iana.org/assignments/media-types/application/vnd.ipld.raw).
620
+
- CAR (`?format=car`)
621
+
- Arbitrary DAG as a verifiable CAR file or a stream, see [application/vnd.ipld.car](https://www.iana.org/assignments/media-types/application/vnd.ipld.car).
622
+
- TAR (`?format=tar`)
623
+
- Deserialized UnixFS files and directories as a TAR file or a stream, see [IPIP-288](https://github.com/ipfs/specs/pull/288)
605
624
606
625
# Appendix: notes for implementers
607
626
@@ -627,13 +646,32 @@ and [DNSLINK_GATEWAY.md](./DNSLINK_GATEWAY.md)).
627
646
628
647
### Traversing remaining path
629
648
630
-
UnixFS pathing over files and directories is the implicit default used for
631
-
resolving content paths that start with `/ipfs/` and `/ipns/`. It allows for
632
-
traversal based on link names, which provides a better user experience than
633
-
low level logical pathing from IPLD:
649
+
After the content root CID is found, the remaining of the path should be traversed
650
+
and resolved. Depending on the data type, that may occur through UnixFS pathing,
651
+
or DAG-JSON, and DAG-CBOR pathing.
652
+
653
+
### Traversing through UnixFS
654
+
655
+
UnixFS is an abstraction over the low level [logical DAG-PB pathing][dag-pb-format]
656
+
from IPLD, providing a better user experience:
634
657
635
658
- Example of UnixFS pathing: `/ipfs/cid/dir-name/file-name.txt`
636
659
660
+
For more details regarding DAG-PB pathing, please read the "Path Resolution" section
661
+
of [this document](https://ipld.io/design/tricky-choices/dag-pb-forms-impl-and-use/#path-resolution).
662
+
663
+
### Traversing through DAG-JSON and DAG-CBOR
664
+
665
+
Traversing through [DAG-JSON][dag-json] and [DAG-CBOR][dag-cbor] is possible
666
+
through fields that encode a link:
667
+
668
+
- DAG-JSON: link are represented as a base encoded CID under the `/` reserved
669
+
namespace, see [specification](https://ipld.io/specs/codecs/dag-json/spec/#links).
670
+
- DAG-CBOR: links are tagged with CBOR tag 42, indicating that they encode a CID,
671
+
see [specification](https://ipld.io/specs/codecs/dag-cbor/spec/#links).
672
+
673
+
Note: pathing into [IPLD Kind](https://ipld.io/docs/data-model/kinds/) other than Link (CID) is not supported at the moment. Implementations should return HTTP 501 Not Implemented when fully resolved content path has any remainder left. This feature may be specified in a future [IPIP that introduces data onboarding](https://github.com/ipfs/in-web-browsers/issues/189) and [IPLD Patch](https://ipld.io/specs/patch/) semantics.
674
+
637
675
### Handling traversal errors
638
676
639
677
Gateway MUST respond with HTTP error when it is not possible to traverse the requested content path:
@@ -693,15 +731,24 @@ It should be always fast, even when a directory has 10k of items.
693
731
The usual optimizations involve:
694
732
695
733
- Skipping size and type resolution for child UnixFS items, and using `Tsize`
696
-
from [logical format](https://ipld.io/specs/codecs/dag-pb/spec/#logical-format)
697
-
instead, allows gateway to respond much faster, as it no longer need to fetch
698
-
root nodes of child items.
699
-
- Additional information about child nodes can be fetched lazily
700
-
with JS, but only for items in the browser's viewport.
734
+
from [logical format][dag-pb-format] instead, allows gateway to respond much
735
+
faster, as it no longer need to fetch root nodes of child items.
736
+
- Instead of showing "file size" GUIs should show "IPFS DAG size". This
737
+
remains useful for quick inspection, but does not require fetching child
738
+
blocks, making directory listing fast, even with tens of thousands of
0 commit comments