-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: use blockstore sessions Adds a configurable session cache that creates sessions based on the base URL of the requested resource. E.g. `https://Qmfoo.ipfs.gateway.com/foo.txt` and`https://Qmfoo.ipfs.gateway.com/bar.txt` will be loaded from the same session. Defaults to 100 sessions maximum with a TTL of one minute. These are arbitrary numbers that will require some tweaking. * chore: update helia version * chore: change cache key format * chore: linting * chore: remove pre-releases * chore: update versions * test: remove cleanup fn call --------- Co-authored-by: Russell Dempsey <[email protected]>
- Loading branch information
1 parent
f7ac2e7
commit 541dd64
Showing
15 changed files
with
409 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,10 @@ describe('@helia/verified-fetch - unixfs directory', () => { | |
before(async () => { | ||
verifiedFetch = await createVerifiedFetch({ | ||
gateways: ['http://127.0.0.1:8180'], | ||
routers: [] | ||
routers: [], | ||
allowInsecure: true, | ||
allowLocal: true | ||
}) | ||
verifiedFetch = await createVerifiedFetch() | ||
}) | ||
|
||
after(async () => { | ||
|
@@ -26,7 +27,11 @@ describe('@helia/verified-fetch - unixfs directory', () => { | |
'http://example.com/ipfs/bafybeifq2rzpqnqrsdupncmkmhs3ckxxjhuvdcbvydkgvch3ms24k5lo7q' | ||
].forEach((url: string) => { | ||
it(`request to unixfs directory with ${url} should return a 301 with a trailing slash`, async () => { | ||
const response = await verifiedFetch(url, { redirect: 'manual' }) | ||
const response = await verifiedFetch(url, { | ||
redirect: 'manual', | ||
allowLocal: true, | ||
allowInsecure: true | ||
}) | ||
expect(response).to.be.ok() | ||
expect(response.status).to.equal(301) | ||
expect(response.headers.get('location')).to.equal(`${url}/`) | ||
|
@@ -38,20 +43,29 @@ describe('@helia/verified-fetch - unixfs directory', () => { | |
describe('XKCD Barrel Part 1', () => { | ||
it('fails to load when passed the root', async () => { | ||
// The spec says we should generate HTML with directory listings, but we don't do that yet, so expect a failure | ||
const resp = await verifiedFetch('ipfs://QmbQDovX7wRe9ek7u6QXe9zgCXkTzoUSsTFJEkrYV1HrVR') | ||
const resp = await verifiedFetch('ipfs://QmbQDovX7wRe9ek7u6QXe9zgCXkTzoUSsTFJEkrYV1HrVR', { | ||
allowLocal: true, | ||
allowInsecure: true | ||
}) | ||
expect(resp).to.be.ok() | ||
expect(resp.status).to.equal(501) // TODO: we should do a directory listing instead | ||
}) | ||
|
||
it('can return a string for unixfs pathed data', async () => { | ||
const resp = await verifiedFetch('ipfs://QmbQDovX7wRe9ek7u6QXe9zgCXkTzoUSsTFJEkrYV1HrVR/1 - Barrel - Part 1 - alt.txt') | ||
const resp = await verifiedFetch('ipfs://QmbQDovX7wRe9ek7u6QXe9zgCXkTzoUSsTFJEkrYV1HrVR/1 - Barrel - Part 1 - alt.txt', { | ||
allowLocal: true, | ||
allowInsecure: true | ||
}) | ||
expect(resp).to.be.ok() | ||
const text = await resp.text() | ||
expect(text).to.equal('Don\'t we all.') | ||
}) | ||
|
||
it('can return an image for unixfs pathed data', async () => { | ||
const resp = await verifiedFetch('ipfs://QmbQDovX7wRe9ek7u6QXe9zgCXkTzoUSsTFJEkrYV1HrVR/1 - Barrel - Part 1.png') | ||
const resp = await verifiedFetch('ipfs://QmbQDovX7wRe9ek7u6QXe9zgCXkTzoUSsTFJEkrYV1HrVR/1 - Barrel - Part 1.png', { | ||
allowLocal: true, | ||
allowInsecure: true | ||
}) | ||
expect(resp).to.be.ok() | ||
const imgData = await resp.blob() | ||
expect(imgData).to.be.ok() | ||
|
@@ -64,7 +78,9 @@ describe('@helia/verified-fetch - unixfs directory', () => { | |
await verifiedFetch.stop() | ||
verifiedFetch = await createVerifiedFetch({ | ||
gateways: ['http://127.0.0.1:8180'], | ||
routers: [] | ||
routers: ['http://127.0.0.1:8180'], | ||
allowInsecure: true, | ||
allowLocal: true | ||
}, { | ||
contentTypeParser: (bytes) => { | ||
return filetypemime(bytes)?.[0] | ||
|
@@ -73,7 +89,10 @@ describe('@helia/verified-fetch - unixfs directory', () => { | |
}) | ||
|
||
it('can return an image content-type for unixfs pathed data', async () => { | ||
const resp = await verifiedFetch('ipfs://QmbQDovX7wRe9ek7u6QXe9zgCXkTzoUSsTFJEkrYV1HrVR/1 - Barrel - Part 1.png') | ||
const resp = await verifiedFetch('ipfs://QmbQDovX7wRe9ek7u6QXe9zgCXkTzoUSsTFJEkrYV1HrVR/1 - Barrel - Part 1.png', { | ||
allowLocal: true, | ||
allowInsecure: true | ||
}) | ||
// tediously this is actually a jpeg file with a .png extension | ||
expect(resp.headers.get('content-type')).to.equal('image/jpeg') | ||
}) | ||
|
@@ -82,7 +101,10 @@ describe('@helia/verified-fetch - unixfs directory', () => { | |
// from https://github.com/ipfs/gateway-conformance/blob/193833b91f2e9b17daf45c84afaeeae61d9d7c7e/fixtures/trustless_gateway_car/single-layer-hamt-with-multi-block-files.car | ||
describe('HAMT-sharded directory', () => { | ||
it('loads path /ipfs/bafybeidbclfqleg2uojchspzd4bob56dqetqjsj27gy2cq3klkkgxtpn4i/685.txt', async () => { | ||
const resp = await verifiedFetch('ipfs://bafybeidbclfqleg2uojchspzd4bob56dqetqjsj27gy2cq3klkkgxtpn4i/685.txt') | ||
const resp = await verifiedFetch('ipfs://bafybeidbclfqleg2uojchspzd4bob56dqetqjsj27gy2cq3klkkgxtpn4i/685.txt', { | ||
allowLocal: true, | ||
allowInsecure: true | ||
}) | ||
expect(resp).to.be.ok() | ||
const text = await resp.text() | ||
// npx [email protected] cat '/ipfs/bafybeidbclfqleg2uojchspzd4bob56dqetqjsj27gy2cq3klkkgxtpn4i/685.txt' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.