-
Notifications
You must be signed in to change notification settings - Fork 5
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
fix: identity CIDs use contentTypeParser #49
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
import { createHeliaHTTP } from '@helia/http' | ||
import { unixfs } from '@helia/unixfs' | ||
import { stop } from '@libp2p/interface' | ||
import { fileTypeFromBuffer } from '@sgtpooki/file-type' | ||
import { expect } from 'aegir/chai' | ||
import { filetypemime } from 'magic-bytes.js' | ||
import { CID } from 'multiformats/cid' | ||
import Sinon from 'sinon' | ||
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' | ||
import { createVerifiedFetch } from '../src/index.js' | ||
import { VerifiedFetch } from '../src/verified-fetch.js' | ||
import { createHelia } from './fixtures/create-offline-helia.js' | ||
import type { Helia } from '@helia/interface' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use the offline helia. |
||
import type { CID } from 'multiformats/cid' | ||
|
||
describe('content-type-parser', () => { | ||
let helia: Helia | ||
let cid: CID | ||
let verifiedFetch: VerifiedFetch | ||
|
||
beforeEach(async () => { | ||
helia = await createHeliaHTTP() | ||
helia = await createHelia() | ||
const fs = unixfs(helia) | ||
cid = await fs.addByteStream((async function * () { | ||
yield uint8ArrayFromString('H4sICIlTHVIACw', 'base64') | ||
|
@@ -132,4 +132,16 @@ describe('content-type-parser', () => { | |
const resp = await verifiedFetch.fetch(cid) | ||
expect(resp.headers.get('content-type')).to.equal('application/gzip') | ||
}) | ||
|
||
it('can properly set content type for identity CIDs', async () => { | ||
verifiedFetch = new VerifiedFetch({ | ||
helia | ||
}, { | ||
contentTypeParser: async (data) => { | ||
return 'text/plain' | ||
} | ||
}) | ||
const resp = await verifiedFetch.fetch(CID.parse('bafkqablimvwgy3y')) | ||
expect(resp.headers.get('content-type')).to.equal('text/plain') | ||
}) | ||
}) | ||
Comment on lines
+136
to
+146
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test for this fix |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
import { Helia as HeliaClass } from '@helia/utils' | ||
import { MemoryBlockstore } from 'blockstore-core' | ||
import { IdentityBlockstore } from 'blockstore-core/identity' | ||
import { MemoryDatastore } from 'datastore-core' | ||
import type { HeliaHTTPInit } from '@helia/http' | ||
import type { Helia } from '@helia/interface' | ||
|
||
export async function createHelia (init: Partial<HeliaHTTPInit> = {}): Promise<Helia> { | ||
const datastore = new MemoryDatastore() | ||
const blockstore = new MemoryBlockstore() | ||
const blockstore = new IdentityBlockstore(new MemoryBlockstore()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. allow identity blocks when testing |
||
|
||
const helia = new HeliaClass({ | ||
datastore, | ||
|
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.
update to get ipfs/js-stores#303