-
Notifications
You must be signed in to change notification settings - Fork 247
Add HTTP Gateway Specs #283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
a28d1de
feat: initial HTTP gateway specs
lidel 6e24eb0
gateway: add Content-Range
lidel 2e4374f
gateway: registerProtocolHandler uri router
lidel 101fa5e
CODEOWNERS: add lidel for ./http-gateways
lidel 7be0611
gateway: resolving an advanced DNSLink chain
lidel 6a0e2fc
gateway: only-if-cached HEAD behavior
lidel 13f53a8
gateway: suggestions from reviewers
lidel a414411
gateway: include CIDv1 node in summary
lidel af0363e
gateway: reorder URI router section
lidel 4156b43
gateway: add Denylists section
lidel 5435910
gateway: switch only-if-cached miss to 412
lidel 176133a
gateway: apply suggestions from review
lidel cad7046
gateway: apply suggestions from Cloudflare
lidel 04111e6
gateway: add X-Content-Type-Options
lidel ce193e6
gateway: simplify dnslink summary
lidel ffe8af9
gateway: document 412 Precondition Failed
lidel 7e65a76
gateway: link to ipld codecs explainer
lidel e3637e5
gateway: stub about handling traversal errors
lidel 2c731d3
gateway: expand HTTP caching considerations
lidel 6787fd8
gateway: editorial fixes
lidel 25497a4
gateway: expand on Host header parsing
lidel 4b57971
gateway: editorial fixes
lidel 75543c3
gateway: X-Forwarded-Proto and X-Forwarded-Host
lidel 849a7e3
gateway: editorial fixes
lidel e06249f
gateway: X-Trace-Id
lidel 9fc9a9c
gateway: Generated HTML with directory index
lidel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Spec Stewards defined below are automatically requested for review when | ||
| # someone opens a pull request that modifies area of their interest. | ||
|
|
||
| http-gateways/ @lidel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| # DNSLink Gateway Specification | ||
|
|
||
|  | ||
|
|
||
| **Authors**: | ||
|
|
||
| - Marcin Rataj ([@lidel](https://github.com/lidel)) | ||
|
|
||
| ---- | ||
|
|
||
| **Abstract** | ||
|
|
||
| DNSLink Gateway is an extension of | ||
| [PATH_GATEWAY.md](./PATH_GATEWAY.md) | ||
| that enables hosting a specific content path under a specific DNS name. | ||
|
|
||
| This document describes the delta between [PATH_GATEWAY.md](./PATH_GATEWAY.md) and this gateway type. | ||
|
|
||
| In short: | ||
|
|
||
| - HTTP request includes a valid [DNSLink](https://dnslink.dev/) name in `Host` header | ||
| - gateway decides if DNSlink name is allowed | ||
| - gateway resolves DNSLink to an immutable content root identified by a CID | ||
| - HTTP response includes the data for the CID | ||
|
|
||
| # Table of Contents | ||
|
|
||
| - [DNSLink Gateway Specification](#dnslink-gateway-specification) | ||
| - [Table of Contents](#table-of-contents) | ||
| - [HTTP API](#http-api) | ||
| - [`GET /[{path}][?{params}]`](#get-pathparams) | ||
| - [`HEAD /[{path}][?{params}]`](#head-pathparams) | ||
| - [HTTP Request](#http-request) | ||
| - [Request headers](#request-headers) | ||
| - [`Host` (request header)](#host-request-header) | ||
| - [HTTP Response](#http-response) | ||
| - [Appendix: notes for implementers](#appendix-notes-for-implementers) | ||
| - [Leveraging DNS for content routing](#leveraging-dns-for-content-routing) | ||
|
|
||
| # HTTP API | ||
|
|
||
| ## `GET /[{path}][?{params}]` | ||
|
|
||
| Downloads data at specified path under the content path for DNSLink name provided in `Host` header. | ||
|
|
||
| - `path` – optional path to a file or a directory under the content root sent in `Host` HTTP header | ||
| - Example: if `Host: example.com` then the content path to resolve is `/ipns/example.com/{path}` | ||
|
|
||
| ## `HEAD /[{path}][?{params}]` | ||
|
|
||
| Same as GET, but does not return any payload. | ||
|
|
||
| # HTTP Request | ||
|
|
||
| Below MUST be implemented **in addition** to the [HTTP Request section from `PATH_GATEWAY.md`](./PATH_GATEWAY.md#http-request). | ||
|
|
||
| ## Request headers | ||
|
|
||
| ### `Host` (request header) | ||
|
|
||
| Defines the [DNSLink](https://docs.ipfs.io/concepts/glossary/#dnslink) name | ||
| to RECURSIVELY resolve into an immutable `/ipfs/{cid}/` prefix that should | ||
| be prepended to the `path` before the final IPFS content path resolution | ||
| is performed. | ||
|
|
||
| Implementations MUST ensure DNSLink resolution is safe and correct: | ||
| - each DNSLink may include an additional path segment, which MUST be preserved | ||
| - each DNSLink may point at other DNSLink, which means there MUST be a hard | ||
| recursion limit (e.g. 32) and HTTP 400 Bad Request error MUST be returned | ||
| when the limit is reached. | ||
|
|
||
| **Example: resolving an advanced DNSLink chain** | ||
|
|
||
| To illustrate, given DNSLink records: | ||
|
|
||
| - `_dnslink.a.example.com` TXT record: `dnslink=/ipns/b.example.net/path-b` | ||
| - `_dnslink.b.example.net` TXT record: `dnslink=/ipfs/bafy…qy3k/path-c` | ||
|
|
||
| HTTP client sends `GET /path-a` request with `Host: a.example.com` header | ||
| which recursively resolves all DNSLinks and produces the final immutable | ||
| content path: | ||
|
|
||
| 1. `Host` header + `/path-a` → `/ipns/a.example.net/path-a` | ||
| 2. Resolving DNSlink at `a.example.net` replaces `/ipns/a.example.net` with `/ipns/b.example.net/path-b` | ||
| 3. Resolving DNSlink at `b.example.net` replaces `/ipns/b.example.net` with `/ipfs/bafy…qy3k/path-c` | ||
| 4. The immutable content path is `/ipfs/bafy…qy3k/path-c/path-b/path-a` | ||
|
|
||
| # HTTP Response | ||
|
|
||
| Same as [HTTP Response section in `PATH_GATEWAY.md`](./PATH_GATEWAY.md#http-response). | ||
|
|
||
| # Appendix: notes for implementers | ||
|
|
||
| ## Leveraging DNS for content routing | ||
|
|
||
| - It is a good idea to publish | ||
| [DNSAddr](https://github.com/multiformats/multiaddr/blob/master/protocols/DNSADDR.md) | ||
| TXT records with known content providers for the data behind a DNSLink. IPFS | ||
| clients will be able to detect DNSAddr and preconnect to known content | ||
| providers, removing the need for expensive DHT lookup. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.