-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Gateway: fast check if CID is in local datastore cache (only-if-cached) #8783
Comments
About the type, I do not any opinion about which Header to use, anyone of them is fine to me. However about the URL, I think for the exact same reason with support both URL and Header format for the request format, we should support both too.
What about sending a different code to differenciate bad unixfs paths and block not found ? With your proposal it would be impossible to differenciate between accessing I think we should use:
This is a client failure, indicating that the data could not been found and that no redirection is known, which is not true, we know one it would be to use online mode. But I think that out of the |
Makes sense. Also, note from #8880
|
I think I've found an elegant way of doing this without inventing any new headers or fake content types.
We most likely don't want to go with HTTP code 504: anything >499 produces scary red errors in browser console, making it awkward when video player is asking 10 gateways and only 2 have data cached. This is not error state, but part of our content routing cycle. |
* feat: initial HTTP gateway specs This adds gateway specs under ./http-gateways directory. The aim is to document _current_ behavior (implementation in go-ipfs 0.13) and switch the way we do the gateway work to be specs-driven. Long term goal is to provide language and implementation agnostic specification that anyone can use to implement compatible gateways. * gateway: add Content-Range * gateway: registerProtocolHandler uri router * CODEOWNERS: add lidel for ./http-gateways * gateway: resolving an advanced DNSLink chain * gateway: only-if-cached HEAD behavior * gateway: suggestions from reviewers Co-authored-by: Adrian Lanzafame <[email protected]> Co-authored-by: Vasco Santos <[email protected]> Co-authored-by: Oli Evans <[email protected]> * gateway: include CIDv1 node in summary * gateway: reorder URI router section As suggested in #283 (comment) * gateway: add Denylists section * gateway: switch only-if-cached miss to 412 Rationale: ipfs/kubo#8783 (comment) * gateway: apply suggestions from review Co-authored-by: Thibault Meunier <[email protected]> * gateway: apply suggestions from Cloudflare #283 (review) * gateway: add X-Content-Type-Options * gateway: simplify dnslink summary https://github.com/ipfs/specs/pull/283/files#r898709569 * gateway: document 412 Precondition Failed https://github.com/ipfs/specs/pull/283/files#r898686654 * gateway: link to ipld codecs explainer https://github.com/ipfs/specs/pull/283/files#r898687052 * gateway: stub about handling traversal errors https://github.com/ipfs/specs/pull/283/files#r892845860 * gateway: expand HTTP caching considerations * gateway: editorial fixes Co-authored-by: Steve Loeppky <[email protected]> * gateway: expand on Host header parsing https://github.com/ipfs/specs/pull/283/files#r898703765 * gateway: editorial fixes * gateway: X-Forwarded-Proto and X-Forwarded-Host * gateway: editorial fixes * gateway: X-Trace-Id optional header suggested in: #283 (comment) rationale: having specific name as a suggestion of 'best practice' in the specs will simplify debugging across ecosystem * gateway: Generated HTML with directory index Synthesis of ideas from: ipfs/kubo#8455 and ipfs/kubo#9058 Co-authored-by: Adrian Lanzafame <[email protected]> Co-authored-by: Vasco Santos <[email protected]> Co-authored-by: Oli Evans <[email protected]> Co-authored-by: Thibault Meunier <[email protected]> Co-authored-by: Steve Loeppky <[email protected]>
PR ready for review in #9082 |
Ecosystem context
Raw block and CAR stream Gateway response types are added in #8758 and https://github.com/ipfs/go-ipfs/issues/8769.
This unlocks exciting features to happen in IPFS ecosystem:
What is missing
Ability to do a quick test if data behind a CID is already present in Gateway's local cache
Essentially an equivalent for what we already can test in CLI/RPC API:
ipfs block get --offline /ipfs/{cid}
→ errors if block is not present locallyipfs dag stat --offline /ipfs/{cid}
→ errors if full DAG is not present locallyI think doing this only per block should be enough – checking if entire DAG is present may be too expensive / overkill in practice.
Why we need it
How to implement this
HTTP HEAD
request is a good candidate. It does not return any payload, only HTTP headers.Right now,
HEAD
request is being used for shallow preload of root blocks: depending on resource type, it usually triggers block fetch events along the requested content path up to the root block of the final path segment. We can't change this, because it works as expected – clients use HEAD to readContent-Length
of unixfs files and raw blocks, and that is why root block has to be fetched if it is not present in the local datastore.This means we need some additional flag to signal we want to do a local datastore check without triggering any additional work.
How to indicate "no-remote-fetch" when sending HTTP HEAD request for
/ipfs/{cid}
?Perhaps RFC 7234#only-if-cached?
Cache-Control: only-if-cached
could be used for requesting payload only if the gateway already has the data and can return it immediately. If data is not cached locally, and the response requires an expensive remote fetch, a 504 (Gateway Timeout) status code should be returned.HEAD
+Cache-Control: only-if-cached
+ optionalAccept
seem to cover the needs of light clients.The text was updated successfully, but these errors were encountered: