Skip to content
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

Add etag and other caching headers to all content addressed gets in api #3543

Closed
ianopolous opened this issue Dec 27, 2016 · 5 comments
Closed

Comments

@ianopolous
Copy link
Member

ianopolous commented Dec 27, 2016

Version information:

N/A

Type: Enhancement

Priority:

P3

Description:

After discussion in irc, I'm submitting this feature request. The origin of this requirement is the following: Previously we've had our own http api for Peergos with caching working fine, but now we're trying to move to match IPFS' http api to allow us to self host from within IPFS. However it seems that the object api currently doesn't include etag headers and are not cached. Local tests however would suggest that even including them will not make the browser (chrome only tested) cache the requests. My guess is that the hash will need to be included in the path, rather than the query to get the caching working.

e.g. https://ipfs.io/api/v0/object/get?stream-channels=true&arg=QmTkzDwWqPbnAh5YiV5VwcTLnGdwSNsNTn2aDxdXBFca7D

Currently we are using solely the ipfs object api (get, data, and the writing calls new, addLink, setData) However, I'd like to migrate to the simpler dag api, once it supports cbor, but it seems to have the same problem.

@ianopolous
Copy link
Member Author

An easy way to demonstrate the browser's non caching behaviour, even with the correct etag header present is
https://ipfs.io/ipfs/QmTkzDwWqPbnAh5YiV5VwcTLnGdwSNsNTn2aDxdXBFca7D?key=thiswontbecached
(chrome won't cache this, ... though it seems firefox will, so maybe the non caching with etag is a chrome bug :-( )

@ianopolous
Copy link
Member Author

After talking to a chromium engineer it turns out this is by design. Pressing enter in the url bar, or F5 will ignore the cache, even if the url is set to cache for a year with immutable and etag set. It should be returned from cache when called within a page, either as an ajax call or as a subresource. So it really is just a matter of setting the same headers on object calls.

@whyrusleeping whyrusleeping added the help wanted Seeking public contribution on this issue label Sep 2, 2017
@lidel
Copy link
Member

lidel commented Oct 18, 2018

I agree, we could provide significant optimization by adding cache-control: immutable to responses with immutable data from API endpoints at:

  • /api/v0/object/get/
  • /api/v0/dag/get/

However, immutable flag should be set only if:

@ianopolous
Copy link
Member Author

We no longer use the object api, but have replaced it with the block api, but the same thing applies there.

@Stebalien Stebalien removed the help wanted Seeking public contribution on this issue label Aug 7, 2019
@lidel
Copy link
Member

lidel commented Jun 12, 2020

We discussed this during Friday issue triage and decided these additional HTTP semantics do not belong under /api/v0:

The HTTP API under /api/v0/ is an RPC-style API over HTTP, not a REST API.
https://docs.ipfs.io/reference/http/api/

In short: if one needs caching of RPC API call responses, then it needs to happen at application level.


Note that HTTP cache control is already supported on gateway's /ipfs/ paths.

@ianopolous is getting JSON representation of directory listing the only reason for filling this issue?

I believe we could add support for returning JSON instead of HTML for dir listings
(triggered by passing Accept: application/json header or &enc=json param)
Feel free to PR or open a separate issue for adding that feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants