-
-
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: use CID as an ETag strong validator #3869
Conversation
* Always use the fully resolved CID from api.ResolveNode as the ETag (also for IPNS). * Format the result as a valid "Strong Validator" (double quotes around the encoded CID). Fixes ipfs#3868 License: MIT Signed-off-by: Remco Bloemen <remco@2π.com>
This implementation effectively calls |
Inlining The gateway's directory listings are another, already existing case of double-read. Other options for making this more efficient:
I kinda like the latter, I can see these come in handy when working with ipld nodes, but not actually wanting to store them into ipfs just to work with them. We'd need to look at how this would play with other parts of the Core API (object, block, dag). But I'm also fine with leaving the fix to double-reads to another PR. |
I like the idea of passing ipld.Node to the unixfs functions. But I don't feel confident enough to change their APIs. I think I have a simpler solution, let me try something. |
0db1fe1
to
606f7c4
Compare
core/corehttp/gateway_handler.go
Outdated
defer dr.Close() | ||
case coreiface.ErrIsDir: | ||
dir = true | ||
break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need for break here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's gone now :)
606f7c4
to
2b4219e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still want @lgierth to CR it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks a bunch! One tiny change, otherwise it LGTM 👍
core/corehttp/gateway_handler.go
Outdated
case coreiface.ErrOffline: | ||
if !i.node.OnlineMode() { | ||
webError(w, "ipfs cat "+urlPath, err, http.StatusServiceUnavailable) | ||
webError(w, "ipfs resolve "+urlPath, err, http.StatusServiceUnavailable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the CLI equivalent of this is ipfs resolve -r
:) Better get it right so that the few who actually paste this into a terminal don't get confused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Didn't know it was meant to paste in terminals—great feature :)
2b4219e
to
abac0f8
Compare
You've changed the error message but not the test and not it is failing. |
Instead of resolving a node, we resolve a path. This resolved path is then re-used for Cat and Ls. This way, a resolve operation is only done once. The error messages for a failed resolve is changed from `ipfs cat …` to `ipfs resolve …` to better reflect the API calls. The test is updated accordingly. License: MIT Signed-off-by: Remco Bloemen <remco@2π.com>
abac0f8
to
a90f496
Compare
@Kubuxu Sorry, fixed it now! |
Looks like something is wrong with the core API, I will explore. |
And now it works. Looks like it is combination of timeouts, short ipfs.io TTL and not so great connection. Not related to this PR. |
@recmo could you resolve the conflict by rebase. It should be quite easy. Sorry about that. |
I was able to resolve the conflict via GH UI, not sure it was the best idea as it created merge commit. |
@recmo thank you very much. It should significantly increase performance of non-local gateways and cache proxies. |
Thanks for merging! This will help our deployment significantly. |
gateway: use CID as an ETag strong validator This commit was moved from ipfs/kubo@b3c20aa
Always use the fully resolved CID from api.ResolveNode
as the ETag (also for IPNS).
Format the result as a valid "Strong Validator"
(double quotes around the encoded CID).
Fixes #3868
License: MIT
Signed-off-by: Remco Bloemen <remco@2π.com>