Skip to content

Commit dd84771

Browse files
committed
feat(http-gateways): add trustless parameters
Add specification for queries for verifiable CAR requests
1 parent 6a5bd43 commit dd84771

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

src/http-gateways/path-gateway.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,30 @@ This is a URL-friendly alternative to sending an [`Accept`](#accept-request-head
205205
- `format=json``Accept: application/json`
206206
- `format=cbor``Accept: application/cbor`
207207

208+
## Query Parameters for CAR Requests
209+
210+
The following query parameters are only available for requests made with either a `format=car` query parameter or an `Accept: application/vnd.ipld.car` request header. These parameters modify shape of the IPLD graph returned within the car file
211+
212+
### `car-scope` (request query parameter)
213+
214+
Optional, `car-scope=(block|file|all)` with default value 'all', describes the shape of the dag fetched the terminus of the specified path whose blocks are included in the returned CAR file after the blocks required to traverse path segments.
215+
216+
`block` - Only the root block at the end of the path is returned After blocks required to verify the specified path segments.
217+
218+
`file` - For queries that traverse UnixFS data, `file` roughly means return blocks needed to verify the end of the path as a filesystem entity. In other words, all the blocks needed 'cat' a UnixFS file at the end of the specified path, or to 'ls' a UnixFS directory at the end of the specified path. For all queries that do not reference non-UnixFS data, `file` is equivalent to `block`
219+
220+
`all` - Transmit the entire contiguous DAG that begins at the end of the path query, after blocks required to verify path segments
221+
222+
### `bytes` (request query parameter)
223+
224+
Optional, `bytes=x:y` with default value `0:*`. When the entity at the end of the end of the specified path can be intepreted as a contingous array of bytes (such as a UnixFS file), returns only the blocks required to verify the specified byte range of said entity. Put another way, the `bytes` parameters can serve as a trustless form of an HTTP range request. If the entity at the end of the path cannot be interpreted as a continguous array of bytes (such as a CBOR/JSON map), this parameter has no effect. Allowed values for `x` and `y` are positive integers where y >= x, which limit the return blocks to needed to satify the range [x, y]. In addition the following additional values are permitted:
225+
226+
- `*` can be substituted for end-of-file
227+
- `?bytes=0:*` is the entire file (i.e. to fulfill HTTP Range Request `x-` requests)
228+
- Negative numbers can be used for referring to bytes from the end of a file
229+
- `?bytes=-1024:*` is the last 1024 bytes of a file (i.e. to fulfill HTTP Range Request `-y` requests)
230+
- It is also permissible (unlike with HTTP Range Requests) to ask for the range of 500 bytes from the beginning of the file to 1000 bytes from the end by `?bytes=499:-1000`
231+
208232
<!-- TODO Planned: https://github.com/ipfs/go-ipfs/issues/8769
209233
- `selector=<cid>` can be used for passing a CID with [IPLD selector](https://ipld.io/specs/selectors)
210234
- Selector should be in dag-json or dag-cbor format
@@ -567,7 +591,10 @@ The following response types require an explicit opt-in, can only be requested w
567591
- Raw Block (`?format=raw`)
568592
- Opaque bytes, see [application/vnd.ipld.raw](https://www.iana.org/assignments/media-types/application/vnd.ipld.raw).
569593
- CAR (`?format=car`)
570-
- 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).
594+
- A CAR file or a stream that contains all blocks required to trustless verify the expressed query, see [application/vnd.ipld.car](https://www.iana.org/assignments/media-types/application/vnd.ipld.car).
595+
- Must contain, as the very first block, the block that hashes to the content root CID
596+
- Must contain, immediately following the root block, all blocks encountered while traversing the expressed path in the order they were traversed
597+
- Must contain, immediately following traversed path blocks, appropriate blocks in depth first traversal order required to verify the query expressed at the terminus of the path in [query parameters](#query-parameters-for-car-requests)
571598
- TAR (`?format=tar`)
572599
- Deserialized UnixFS files and directories as a TAR file or a stream, see [IPIP-288](https://github.com/ipfs/specs/pull/288)
573600

src/http-gateways/trustless-gateway.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,36 @@ editors:
88

99
# Trustless Gateway Specification
1010

11-
Trustless Gateway is a minimal _subset_ of :cite[path-gateway]
11+
Trustless Gateway is a _subset_ of :cite[path-gateway]
1212
that allows light IPFS clients to retrieve data behind a CID and verify its
1313
integrity without delegating any trust to the gateway itself.
1414

1515
The minimal implementation means:
1616

17-
- data is requested by CID, only supported path is `/ipfs/{cid}`
18-
- no path traversal or recursive resolution, no UnixFS/IPLD decoding server-side
1917
- response type is always fully verifiable: client can decide between a raw block or a CAR stream
18+
- no UnixFS/IPLD decoding server-side
19+
- for CAR files:
20+
- the behavior is identical to :cite[path-gateway]
21+
- for raw blocks:
22+
- data is requested by CID, only supported path is `/ipfs/{cid}`
23+
- no path traversal or recursive resolution,
2024

2125
# HTTP API
2226

2327
A subset of "HTTP API" of :cite[path-gateway].
2428

25-
## `GET /ipfs/{cid}[?{params}]`
29+
## `GET /ipfs/{cid}[/{path}][?{params}]`
2630

27-
Downloads data at specified CID.
31+
Downloads data at specified **immutable** content path.
2832

29-
## `HEAD /ipfs/{cid}[?{params}]`
33+
Path parameters are only permitted for requests that specify CAR format. For RAW requests, only `GET /ipfs/{cid}[?{params}]` is supported
34+
35+
## `HEAD /ipfs/{cid}[/{path}][?{params}]`
3036

3137
Same as GET, but does not return any payload.
3238

39+
Path parameters are only permitted for requests that specify CAR format. For RAW requests, only `HEAD /ipfs/{cid}[?{params}]` is supported
40+
3341
# HTTP Request
3442

3543
Same as in :cite[path-gateway], but with limited number of supported response types.

0 commit comments

Comments
 (0)