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

Gateway: client opt-in JSON responses for directory listing #7552

Open
lucidNTR opened this issue Jul 19, 2020 · 7 comments
Open

Gateway: client opt-in JSON responses for directory listing #7552

lucidNTR opened this issue Jul 19, 2020 · 7 comments
Labels
effort/days Estimated to take multiple days, but less than a week exp/intermediate Prior experience is likely helpful help wanted Seeking public contribution on this issue kind/enhancement A net-new feature or improvement to an existing feature kind/feature A new feature P3 Low: Not priority right now status/ready Ready to be worked topic/gateway Topic gateway

Comments

@lucidNTR
Copy link

Followup to #7431, that was closed but had the valuable feature of accessing json manifest of folder

requests to a "folder", especially the root of a folder published to ipns such as http://bafzbeibxww7y6v5metkgmxeqkvls74uqvptbhommrb5b7xianigcicdvuy.ipns.localhost/
should be served the same response as
https://ipfs.io/api/v0/ls?arg=bafzbeibxww7y6v5metkgmxeqkvls74uqvptbhommrb5b7xianigcicdvuy

IF the accept content type header is set to "application/json" that way there is no interference with existing gateway behaviour and with serving the index.html file at the root

@lucidNTR lucidNTR added kind/feature A new feature need/triage Needs initial labeling and prioritization labels Jul 19, 2020
@lidel lidel added the topic/gateway Topic gateway label Jul 21, 2020
@lidel
Copy link
Member

lidel commented Jul 21, 2020

Thank you for filling this @lucidNTR – below are my thoughts why we should consider this:

On mutability of directory listings

Directory listing is a special type of response returned by the gateway in that it is generated by the gateway itself. Even for immutable /ipfs/, the response can change, because we may update the HTML/CSS.

That is why for directories we don't return cache-control: (..) immutable header

If we add support for JSON response, then we could truly return an immutable response, instead of less permanent Etag-based cache control hint.

Needs: mandatory versioning

The only concern is that doing plain application/json would leak the current schema of /api/v0/ls into Gateway outside /api/v0. What happens when we change the API and introduce /api/v1/ls that produces different JSON?

I think we need to include API version in the request somehow:

  • Accept: application/json;version=0
  • Accept: application/vnd.ipfs.v0+json

so we are able to return clear error when client asks for API response in a version that is no longer supported. Having API version as a part of request would also let us return proper cache control headers that mark response as immutable under /ipfs/*

TLDR: this would be useful feature

Personally, I would be open to a PR that adds this feature, as long versioning is mandatory.
Thoughts @aschmahmann?

@lidel lidel changed the title support the accept content type header set to "application/json" for ipns subdomain requests Gateway: client opt-in JSON responses for directory listing Jul 21, 2020
@lidel lidel added kind/enhancement A net-new feature or improvement to an existing feature need/maintainers-input Needs input from the current maintainer(s) labels Jul 21, 2020
@aschmahmann
Copy link
Contributor

@lidel I'm generally fine if we want to basically alias something we already do (e.g. /api/v0/ls) using accept headers.

A couple thoughts + questions though:

  1. It doesn't seem like it's worth thinking too hard about caching in browsers since if you really wanted caching you could just use a local ipfs daemon.
  2. I'm not very familiar with accept headers, if we were to remove this functionality in the future (or a particular gateway wanted to disable it) what would the result look like?

@lidel
Copy link
Member

lidel commented Jul 22, 2020

  1. Avoiding unnecessary localhost requests still saves some resources, but I agree its diminishing returns in practice :)
  2. If there is no support for Accept header, a regular HTML directory listing would be returned (current behavior)

@aschmahmann
Copy link
Contributor

SGTM then.

If there is no support for Accept header, a regular HTML directory listing would be returned (current behavior)

I assume this is true even if we keep utilizing accept headers but that particular combination is no longer supported, right?

@lidel
Copy link
Member

lidel commented Jul 23, 2020

Yes, the value of Accept from request would need to be a direct match to produce non-HTML response.

@lidel lidel added exp/intermediate Prior experience is likely helpful effort/days Estimated to take multiple days, but less than a week help wanted Seeking public contribution on this issue P3 Low: Not priority right now status/ready Ready to be worked and removed need/maintainers-input Needs input from the current maintainer(s) need/triage Needs initial labeling and prioritization labels Aug 14, 2020
@lidel
Copy link
Member

lidel commented Dec 8, 2020

Note to self: if we enable this via Accept header, make sure "version" format follows same convention as CAR format type from ipfs/in-web-browsers#170 (that is, if CAR itself ends up versioned - TBD).

@lidel
Copy link
Member

lidel commented Jun 30, 2021

#8234 could be relevant here:

if we find a way to represent dag-pb directory as dag-cbor document, then ?format=dag-json could be an elegant way for supporting JSON responses for directory listing

Going with dag-cbor representation not only solves versioning, but makes it possible to programmatically traverse unixfs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/days Estimated to take multiple days, but less than a week exp/intermediate Prior experience is likely helpful help wanted Seeking public contribution on this issue kind/enhancement A net-new feature or improvement to an existing feature kind/feature A new feature P3 Low: Not priority right now status/ready Ready to be worked topic/gateway Topic gateway
Projects
None yet
Development

No branches or pull requests

3 participants