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

feat: support requesting raw IPNS records in @helia/verified-fetch #443

Merged
merged 11 commits into from
Feb 22, 2024

Conversation

achingbrain
Copy link
Member

Adds support for the application/vnd.ipfs.ipns-record Accept header to return raw IPNS records.

Let users get raw data back from CIDs that would otherwise trigger
decoding as JSON or CBOR etc by specifying an `Accept` header.

```typescript
const res = await verifiedFetch(cid, {
  headers: {
    accept: 'application/octet-stream'
  }
})
console.info(res.headers.get('accept')) // application/octet-stream
```

Make sure the content-type matches the accept header:

```typescript
const res = await verifiedFetch(cid, {
  headers: {
    accept: 'application/vnd.ipld.raw'
  }
})
console.info(res.headers.get('accept')) // application/vnd.ipld.raw
```

Support multiple values, match the first one:

```typescript
const res = await verifiedFetch(cid, {
  headers: {
    accept: 'application/vnd.ipld.raw, application/octet-stream, */*'
  }
})
console.info(res.headers.get('accept')) // application/vnd.ipld.raw
```

If they specify an Accept header we can't honor, return a [406](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/406):

```typescript
const res = await verifiedFetch(cid, {
  headers: {
    accept: 'application/what-even-is-this'
  }
})
console.info(res.status) // 406
```
Adds support for the `application/vnd.ipld.car` accept header to
allow downloading CAR files of DAGs.
Adds support for downloading tar archives of UnixFS directories
Adds support for the `application/vnd.ipfs.ipns-record` Accept header
to return raw IPNS records.
@achingbrain achingbrain requested a review from a team as a code owner February 21, 2024 14:38
@@ -153,17 +153,20 @@
"@ipld/dag-json": "^10.2.0",
"@ipld/dag-pb": "^4.1.0",
"@libp2p/interface": "^1.1.2",
"@libp2p/kad-dht": "^12.0.7",
Copy link
Member Author

Choose a reason for hiding this comment

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

This is only here to be able to deserialize stored IPNS records that are wrapped in a libp2p record.

Longer term we may wish to split the libp2p record code out of the dht code to make the bundle size a bit smaller.

Copy link
Member

Choose a reason for hiding this comment

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

Do we have a tracking issue for this?

Copy link
Member

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

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

🎉🎉

Base automatically changed from feat/download-tars-from-verified-fetch to main February 22, 2024 10:55
@achingbrain achingbrain merged commit 28d62f7 into main Feb 22, 2024
18 checks passed
@achingbrain achingbrain deleted the feat/verified-fetch-ipns-records branch February 22, 2024 11:32
@achingbrain achingbrain mentioned this pull request Feb 22, 2024
await stop(helia, verifiedFetch)
})

it('should support fetching a raw IPNS record', async () => {
Copy link
Member

@2color 2color Feb 23, 2024

Choose a reason for hiding this comment

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

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

Successfully merging this pull request may close these issues.

3 participants