Skip to content

Commit e1af6e4

Browse files
committed
ipip-402: clarify error scenarios
#402 (review)
1 parent 61d1088 commit e1af6e4

File tree

1 file changed

+41
-16
lines changed

1 file changed

+41
-16
lines changed

src/http-gateways/trustless-gateway.md

+41-16
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,29 @@ When present, returned `Etag` must include unique prefix based on the passed sco
9999

100100
### :dfn[entity-bytes] (request query parameter)
101101

102-
Optional, `entity-bytes=from:to` with the default value `0:*`, only available for CAR requests.
103-
Serves as a trustless form of an HTTP Range Request.
102+
The optional `entity-bytes=from:to` parameter is available only for CAR
103+
requests.
104104

105-
When the terminating entity at the end of the specified content path can be
106-
interpreted as a continuous array of bytes (such as a UnixFS file), returns
107-
only the minimal set of blocks required to verify the specified byte range of
108-
said entity.
105+
It implies `dag-scope=entity` and serves as a trustless equivalent of an HTTP
106+
Range Request.
109107

110-
Allowed values for `from` and `to` are positive integers where `to` >= `from`, which
111-
limit the return blocks to needed to satisfy the range `[from,to]`:
108+
When the terminating entity at the end of the specified content path:
112109

113-
- `from` value gives the byte-offset of the first byte in a range.
114-
- `to` value gives the byte-offset of the last byte in the range; that is,
115-
the byte positions specified are inclusive. Byte offsets start at zero.
110+
- can be interpreted as a continuous array of bytes (such as a UnixFS file), a
111+
Gateway MUST return only the minimal set of blocks necessary to verify the
112+
specified byte range of that entity.
113+
114+
- cannot be interpreted as a continuous array of bytes (such as a DAG-CBOR/JSON
115+
map or UnixFS directory), the parameter MUST be ignored, and the request is
116+
equivalent to `dag-scope=entity`.
116117

117-
If the entity at the end of the path cannot be interpreted as a continuous
118-
array of bytes (such as a DAG-CBOR/JSON map, or UnixFS directory), this
119-
parameter has no effect.
118+
Allowed values for `from` and `to` follow a subset of section 14.1.2 from
119+
:cite[rfc9110], where they are defined as offset integers that limit the
120+
returned blocks to only those necessary to satisfy the range `[from,to]`:
121+
122+
- `from` value gives the byte-offset of the first byte in a range.
123+
- `to` value gives the byte-offset of the last byte in the range;
124+
that is, the byte positions specified are inclusive.
120125

121126
The following additional values are supported:
122127

@@ -129,7 +134,28 @@ The following additional values are supported:
129134
range of 500 bytes from the beginning of the file to 1000 bytes from the
130135
end: `entity-bytes=499:-1000`
131136

132-
When present, returned `Etag` must include unique prefix based on the passed range.
137+
A Gateway MUST augment the returned `Etag` based on the passed `entity-bytes`.
138+
139+
A Gateway SHOULD return an HTTP 400 Bad Request error when the requested range
140+
cannot be parsed as valid offset positions.
141+
142+
In more nuanced error scenarios, a Gateway MUST return a valid CAR response
143+
that includes enough blocks for the client to understand why the requested
144+
`entity-bytes` was incorrect or why only a part of the requested byte range was
145+
returned:
146+
147+
- If the requested `entity-bytes` resolves to a range that partially falls
148+
outside of the entity's byte range, the response MUST include the subset of
149+
blocks within the entity's bytes.
150+
- This allows clients to request valid ranges of the entity without needing
151+
to know its total size beforehand, and it does not require the Gateway to
152+
buffer the entire entity before returning the response.
153+
154+
- If the requested `entity-bytes` resolves to a zero-length range or falls
155+
fully outside of the entity's bytes, the response is equivalent to
156+
`dag-scope=block`.
157+
- This allows client to produce a meaningful error (e.g, in case of UnixFS,
158+
leverage `Data.blocksizes` information present in the root `dag-pb` block).
133159

134160
# HTTP Response
135161

@@ -207,4 +233,3 @@ of determinism in CAR responses. Please refer to
207233
in this area.
208234

209235
:::
210-

0 commit comments

Comments
 (0)