Skip to content

Commit 0eacf6a

Browse files
committed
ipip-425: Signaling Features on HTTP Gateways
Initial version to kick-off discussion
1 parent fb214ae commit 0eacf6a

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

src/http-gateways/path-gateway.md

+40
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,46 @@ Optional, present in certain response types:
542542
non-executable binary response types are not used in `<script>` and `<style>`
543543
HTML tags.
544544

545+
### `Ipfs-Gateway-Features` (response header)
546+
547+
Optional, this header SHOULD be only returned in response to HTTP `OPTIONS` request.
548+
549+
The value is a list of key-value pairs, as specified by the 5.6.1. Lists section of :cite[rfc9110].
550+
551+
Each feature is indicated by a key and optional value. When more than one value is supported, `|` is used as a separator.
552+
For example:
553+
554+
```
555+
Ipfs-Gateway-Features: foo, bar=1, buzz=a|b|c
556+
```
557+
558+
A Gateway SHOULD use this header to communicate support for specific Gateway feeatures, enabling clients to make better decisions on how to retrieve data.
559+
560+
A Gateway MAY define and return their own features.
561+
562+
A Client MUST send HTTP OPTIONS request to inspect this header before performaning any more expensive feature-detection.
563+
564+
#### Canonical Ipfs-Features values
565+
566+
- `trustless-gateway` for :cite[trustless-gateway]
567+
- `path-proof` indicates support for returning parent blocks up to the terminus element
568+
- `car-version=1|2` indicates CAR support
569+
- `dag-scope=block|entity|all` from :cite[ipip-0402]
570+
- `entity-bytes` from :cite[ipip-0402], implies support for `dag-scope=entity` as well
571+
- `car-block-order=dfs` from :cite[ipip-0412]
572+
- `car-block-dupes=y|n` from :cite[ipip-0412]
573+
- `path-gateway` for deserialized responses defined by :cite[path-gateway]
574+
- `subdomain-gateway=example.com` for :cite[subdomain-gateway] support based on `Host` header
575+
- `dnslink-gateway` for :cite[dnslink-gateway] support based on `Host` header
576+
- `ipns` indicating :cite[ipns-record] support on `/ipns/` content paths
577+
- `dnslink` indicating [DNSLink](https://dnslink.dev) support on `/ipns/` content paths
578+
579+
<!-- TODO do we want these too?
580+
- `multibase` list of prefixes, indicates which multibase encoding are supported in CIDs
581+
- `multihash` indicates which hash functions are supported in CIDs
582+
- `multicodec` indicates which codecs are supported in CIDs
583+
-->
584+
545585
### `Server-Timing` (response header)
546586

547587
Optional. Implementations MAY use this header to communicate one or more

src/ipips/ipip-0425.md

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
title: "IPIP-0425: Signaling Features on HTTP Gateways"
3+
date: 2023-07-06
4+
ipip: proposal
5+
editors:
6+
- name: Marcin Rataj
7+
github: lidel
8+
url: https://lidel.org/
9+
relatedIssues:
10+
- https://github.com/ipfs/specs/pull/402#pullrequestreview-1396116569
11+
- https://github.com/ipfs/specs/pull/412#pullrequestreview-1427137365
12+
order: 425
13+
tags: ['ipips']
14+
---
15+
16+
## Summary
17+
18+
Add ability to query HTTP Gateway for an explicit list of supported features.
19+
20+
## Motivation
21+
22+
A Gateway always ships with an opinionated set of supported hash functions and
23+
IPLD codecs, and the differences between implementations will grow over time.
24+
25+
For example, some legacy gateways may not support newly added features like
26+
`dag-scope` and `entity-bytes` from :cite[ipip-0402] or the ability to get some
27+
block ordering guarantees introduced in :cite[ipip-0412]. Future IPIPs may add
28+
more features and response formats.
29+
30+
We need a light mechanism for clients to detect which gateway supports partial CARs
31+
32+
## Detailed design
33+
34+
This IPIP introduces a set of HTTP headers returned in response to `OPTIONS` request:
35+
36+
The `Ipfs-Gateway-Features` header is used for signalling support for specific Gateway features to the client.
37+
38+
The lack of the header, or missing key-value pair within the header means support status is unknown.
39+
40+
Initial list of key-value pairs is documented in `Ipfs-Gateway-Features` section of :cite[path-gateway]
41+
42+
## Design rationale
43+
44+
There is a good prior art for this in web browsers where HTTP `OPTIONS` method
45+
is used in [CORS Preflight request](https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request)
46+
that checks if the CORS protocol is understood and a server is aware using
47+
specific methods and headers.
48+
49+
The `OPTIONS` request if often sent by web browser anyway, so we would not be
50+
introducing much overhead.
51+
52+
### User benefit
53+
54+
Reduced cost for both client and gateway. Sending `OPTIONS` request will be
55+
very inexpensive, especially when compared with current status quo where a
56+
client has to send at least one request to probe a specific feature like
57+
support forp Blake3 hash function or `dag-scope` or `entity-bytes`.
58+
59+
This translates to decreased latency and ability to choose the best retrieval
60+
strategy faster.
61+
62+
### Compatibility
63+
64+
This IPIP is fully backward-compatible with browsers and existing IPFS
65+
ecosystem. Gateways already return CORS headers with `OPTIONS` responses, we
66+
will simply return additional headers with the same responses.
67+
68+
:::issue
69+
70+
For JavaScript running on web pages to be able to read `Ipfs-Gateway-Features`
71+
header it MUST be safelisted via `Access-Control-Expose-Headers`.
72+
73+
:::
74+
75+
### Security
76+
77+
This IPIP does not introduce any new security concerns. Probing gateway for
78+
supported features and hash functions is already possible via regular `GET`
79+
requests.
80+
81+
### Alternatives
82+
83+
- Exposing the list of suported features via `GET /.well-known/ipfs/gateway/features-TBD` would also work, but:
84+
- introduces surface for path-related deployment bugs, where Nginx is only exposing `/ipfs` namespace – in such case signaling endpoint would not be exposed to the public internet
85+
86+
## Test fixtures
87+
88+
TODO
89+
90+
### Copyright
91+
92+
Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).

0 commit comments

Comments
 (0)