-
Notifications
You must be signed in to change notification settings - Fork 116
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 downloading car files from @helia/verified-fetch #441
Conversation
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 ```
…ader-for-raw-types
Adds support for the `application/vnd.ipld.car` accept header to allow downloading CAR files of DAGs.
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.
Lgtm but a few comments and questions
}()) | ||
|
||
// write the DAG behind `cid` into the writer | ||
c.export(cid, writer, options) |
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.
We may not want to pass full options 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.
We can change it if we need to, my experience has generally been that it's often useful to be able to pass options to sub components whole.
As it stands there's complete overlap between the option types so I think all we'd gain by limiting the option keys is verbosity.
Co-authored-by: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com>
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.
we have a few pending PRs which may change this PR further, but looks really good.
private async handleCar ({ cid, options }: FetchHandlerFunctionArg): Promise<Response> { | ||
const c = car(this.helia) | ||
const stream = toBrowserReadableStream<Uint8Array>(c.stream(cid, options)) | ||
|
||
const response = okResponse(stream) | ||
response.headers.set('content-type', 'application/vnd.ipld.car; version=1') |
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.
This is so much cleaner. very nice
…om-verified-fetch
Adds support for the
application/vnd.ipld.car
accept header to allow downloading CAR files of DAGs.Change checklist