@helia/verified-fetch 0.0.0-8db7792 → 0.0.0-a04e041
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/dist/index.min.js +4 -4
- package/dist/src/index.d.ts +36 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +33 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/utils/get-content-disposition-filename.d.ts +6 -0
- package/dist/src/utils/get-content-disposition-filename.d.ts.map +1 -0
- package/dist/src/utils/get-content-disposition-filename.js +16 -0
- package/dist/src/utils/get-content-disposition-filename.js.map +1 -0
- package/dist/src/utils/parse-url-string.d.ts +2 -0
- package/dist/src/utils/parse-url-string.d.ts.map +1 -1
- package/dist/src/utils/parse-url-string.js +6 -0
- package/dist/src/utils/parse-url-string.js.map +1 -1
- package/dist/src/utils/responses.d.ts +4 -0
- package/dist/src/utils/responses.d.ts.map +1 -0
- package/dist/src/utils/responses.js +21 -0
- package/dist/src/utils/responses.js.map +1 -0
- package/dist/src/utils/select-output-type.d.ts +12 -0
- package/dist/src/utils/select-output-type.d.ts.map +1 -0
- package/dist/src/utils/select-output-type.js +147 -0
- package/dist/src/utils/select-output-type.js.map +1 -0
- package/dist/src/verified-fetch.d.ts +17 -15
- package/dist/src/verified-fetch.d.ts.map +1 -1
- package/dist/src/verified-fetch.js +211 -129
- package/dist/src/verified-fetch.js.map +1 -1
- package/package.json +18 -12
- package/src/index.ts +37 -0
- package/src/utils/get-content-disposition-filename.ts +18 -0
- package/src/utils/parse-url-string.ts +11 -1
- package/src/utils/responses.ts +22 -0
- package/src/utils/select-output-type.ts +166 -0
- package/src/verified-fetch.ts +237 -134
package/README.md
CHANGED
|
@@ -347,6 +347,39 @@ if (res.headers.get('Content-Type') === 'application/json') {
|
|
|
347
347
|
console.info(obj) // ...
|
|
348
348
|
```
|
|
349
349
|
|
|
350
|
+
## The `Accept` header
|
|
351
|
+
|
|
352
|
+
The `Accept` header can be passed to override certain response processing, or to ensure that the final `Content-Type` of the response is the one that is expected.
|
|
353
|
+
|
|
354
|
+
If the final `Content-Type` does not match the `Accept` header, or if the content cannot be represented in the format dictated by the `Accept` header, or you have configured a custom content type parser, and that parser returns a value that isn't in the accept header, a [406: Not Acceptible](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/406) response will be returned:
|
|
355
|
+
|
|
356
|
+
```typescript
|
|
357
|
+
import { verifiedFetch } from '@helia/verified-fetch'
|
|
358
|
+
|
|
359
|
+
const res = await verifiedFetch('ipfs://bafyJPEGImageCID', {
|
|
360
|
+
headers: {
|
|
361
|
+
accept: 'image/png'
|
|
362
|
+
}
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
console.info(res.status) // 406 - the image was a JPEG but we specified PNG as the accept header
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
It can also be used to skip processing the data from some formats such as `DAG-CBOR` if you wish to handle decoding it yourself:
|
|
369
|
+
|
|
370
|
+
```typescript
|
|
371
|
+
import { verifiedFetch } from '@helia/verified-fetch'
|
|
372
|
+
|
|
373
|
+
const res = await verifiedFetch('ipfs://bafyDAGCBORCID', {
|
|
374
|
+
headers: {
|
|
375
|
+
accept: 'application/octet-stream'
|
|
376
|
+
}
|
|
377
|
+
})
|
|
378
|
+
|
|
379
|
+
console.info(res.headers.get('accept')) // application/octet-stream
|
|
380
|
+
const buf = await res.arrayBuffer() // raw bytes, not processed as JSON
|
|
381
|
+
```
|
|
382
|
+
|
|
350
383
|
## Comparison to fetch
|
|
351
384
|
|
|
352
385
|
This module attempts to act as similarly to the `fetch()` API as possible.
|