Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

feat(gateway): X-Ipfs-Path, Etag, Cache-Control, Suborigin #1537

Merged
merged 1 commit into from
Oct 15, 2018

Conversation

lidel
Copy link
Member

@lidel lidel commented Sep 2, 2018

This PR makes js-ipfs Gateway return the same headers as HTTP Gateway exposed by go-ipfs, namely:

  • X-Ipfs-Path: requested IPFS Path of returned resource
  • Etag: multihash of returned payload
  • Cache-Control: disable cache for directory listings and errors,
    enable heavy caching for immutable assets from /ipfs/ namespace
  • Suborigin: use root CID in base32 and literal prefix to conform
    to current suborigin spec (Suborigins  in-web-browsers#66)

cc ipfs/js-ipfs-http-response#10

@ghost ghost assigned lidel Sep 2, 2018
@ghost ghost added the status/in-progress In progress label Sep 2, 2018
Copy link
Member

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@alanshaw alanshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some interop tests on the way for this @lidel? 😉

@@ -120,6 +121,15 @@ module.exports = {

let response = reply(stream2).hold()

// Etag maps directly to an identifier for a specific version of a resource
// TODO: change to .cid.toBaseEncodedString() after switch to new js-ipfs-http-response
response.header('Etag', `"${data.multihash}"`)
Copy link
Member

@alanshaw alanshaw Sep 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is data.multihash already a string?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is a string already. Etag spec requires wrapping it with ""

Note: the source of this value may change after ipfs/js-ipfs-http-response#9 lands – it will add CID object as data.cid. It just needs to be a unique string, so we can use cid or a raw multihash – both are fine for this.

response.header('X-Ipfs-Path', ref)
if (ref.startsWith('/ipfs/')) {
const rootCid = ref.split('/')[2]
const CID = request.server.app.ipfs.types.CID
Copy link
Member

@alanshaw alanshaw Sep 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just require this instead please?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@lidel
Copy link
Member Author

lidel commented Sep 4, 2018

@alanshaw if it is okay to add http gateway tests to the interop repo, I will PR tests there.
(I was under impression it is ipfs-specific on-the-wire test suite, does it include the http-wire?)

Should I PR before or after this one lands?

@alanshaw
Copy link
Member

alanshaw commented Sep 5, 2018

IMHO, yes I it is appropriate to add HTTP interop tests there. I am unaware of a more appropriate place. Although I'm happy for @diasdavid or anyone else to veto :D

If you are going to submit interop tests then I'm happy to merge this and then have it fixed if the interop tests throw something up.

That said, I'd rather not merge this just yet until after 0.32 is released (hopefully tomorrow/Friday).

@lidel
Copy link
Member Author

lidel commented Sep 5, 2018

Sounds good. I've added interop for this to my TODO list.

(We will need HTTP API interop tests for #1540, so this one will not be the only case of looking at HTTP headers)

@lidel
Copy link
Member Author

lidel commented Sep 28, 2018

@alanshaw I noticed there is a lot of code duplication between protocol handler in companion, service worker gateway and a gateway exposed by js-ipfs.

Perhaps instead of this PR, we should go in the direction described in ipfs/js-ipfs-http-response#6?

Would be great to read your thoughts there 🙌

Return the same headers as HTTP Gateway exposed by go-ipfs:
- X-Ipfs-Path: requested IPFS Path of returned resource
- Etag: multihash of returned payload
- Cache-Control: disable cache for directory listings and errors,
  enable heavy caching for immutable assets from /ipfs/ namespace
- Suborigin: use root CID in base32 and literal prefix to conform
  to current suborigin spec

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
@alanshaw alanshaw merged commit fc5bef7 into ipfs:master Oct 15, 2018
@ghost ghost removed the status/in-progress In progress label Oct 15, 2018
@lidel lidel deleted the feat/x-ipfs-path branch October 15, 2018 17:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants