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
Copy file name to clipboardExpand all lines: http-gateways/PATH_GATEWAY.md
+28-18Lines changed: 28 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -186,8 +186,8 @@ For example:
186
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.
187
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
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.
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.
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.
191
191
192
192
### `Range` (request header)
193
193
@@ -590,32 +590,36 @@ A good practice is to always return it with HTTP error [status codes](#response-
590
590
## Response Payload
591
591
592
592
Data sent with HTTP response depends on the type of the requested IPFS resource, and the requested response type.
593
-
The following response formats are selected according to the codec of the resolved CID:
593
+
594
+
By default, implicit deserialized response type is based on `Accept` header and the codec of the resolved CID:
594
595
595
596
- UnixFS, either `dag-pb` (0x70) or `raw` (0x55)
596
-
- File
597
-
- Bytes representing file contents
597
+
- File or `raw` block
598
+
- Bytes representing file/block contents
599
+
- When `Range` is present, only the requested byte range is returned.
598
600
- Directory
599
601
- Generated HTML with directory index (see [additional notes here](#generated-html-with-directory-index))
600
-
- When `index.html` is present, gateway can skip generating directory index and return it instead
602
+
- When `index.html` is present, gateway MUST skip generating directory index and return content from `index.html`instead.
601
603
- JSON (0x0200)
602
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`
603
606
- CBOR (0x51)
604
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`
605
609
- DAG-JSON (0x0129)
606
-
- If the `Accept` header includes `text/html`: generated HTML with options to download DAG-JSON as-is, or converted to DAG-CBOR.
607
-
-Bytes representing a DAG-JSON file, see[application/vnd.ipld.dag-json](https://www.iana.org/assignments/media-types/application/vnd.ipld.dag-json)
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)
608
612
- DAG-CBOR (0x71)
609
-
- If the `Accept` header includes `text/html`: generated HTML with options to download DAG-CBOR as-is, or converted to DAG-JSON.
610
-
-Bytes representing a DAG-CBOR file, see[application/vnd.ipld.dag-cbor](https://www.iana.org/assignments/media-types/application/vnd.ipld.dag-cbor)
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)
611
615
612
-
The following response types are opt-in, can only be requested with [`format`](#format-request-query-parameter) query parameter or [`Accept`](#accept-request-header) header:
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:
613
617
614
-
- Raw Block
618
+
- Raw Block (`?format=raw`)
615
619
- Opaque bytes, see [application/vnd.ipld.raw](https://www.iana.org/assignments/media-types/application/vnd.ipld.raw).
616
-
- CAR
620
+
- CAR (`?format=car`)
617
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).
618
-
- TAR
622
+
- TAR (`?format=tar`)
619
623
- Deserialized UnixFS files and directories as a TAR file or a stream, see [IPIP-288](https://github.com/ipfs/specs/pull/288)
620
624
621
625
# Appendix: notes for implementers
@@ -642,7 +646,7 @@ and [DNSLINK_GATEWAY.md](./DNSLINK_GATEWAY.md)).
642
646
643
647
### Traversing remaining path
644
648
645
-
After the content route is found, the remaining of the path should be traversed
649
+
After the content root CID is found, the remaining of the path should be traversed
646
650
and resolved. Depending on the data type, that may occur through UnixFS pathing,
647
651
or DAG-JSON, and DAG-CBOR pathing.
648
652
@@ -666,7 +670,7 @@ namespace, see [specification](https://ipld.io/specs/codecs/dag-json/spec/#links
666
670
- DAG-CBOR: links are tagged with CBOR tag 42, indicating that they encode a CID,
667
671
see [specification](https://ipld.io/specs/codecs/dag-cbor/spec/#links).
668
672
669
-
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 and [IPLD Patch](https://ipld.io/specs/patch/) semantics.
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.
670
674
671
675
### Handling traversal errors
672
676
@@ -729,8 +733,14 @@ The usual optimizations involve:
729
733
- Skipping size and type resolution for child UnixFS items, and using `Tsize`
730
734
from [logical format][dag-pb-format] instead, allows gateway to respond much
731
735
faster, as it no longer need to fetch root nodes of child items.
732
-
- Additional information about child nodes can be fetched lazily
733
-
with JS, but only for items in the browser's viewport.
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