@helia/verified-fetch
Version:
A fetch-like API for obtaining verified & trustless IPFS content on the web
33 lines • 1.29 kB
JavaScript
const getPrefix = ({ weak, reqFormat }) => {
if (reqFormat === 'tar' || reqFormat === 'car' || reqFormat === 'ipns-record' || weak === true) {
return 'W/';
}
return '';
};
const getFormatSuffix = ({ reqFormat }) => {
if (reqFormat == null) {
return '';
}
if (reqFormat === 'tar') {
return '.x-tar';
}
return `.${reqFormat}`;
};
/**
* etag
* you need to wrap cid with ""
* we use strong Etags for immutable responses and weak one (prefixed with W/ ) for mutable/generated ones (ipns, car, tar, and generated HTML).
* block and car responses should have different etag than deserialized one, so you can add some prefix like we do in existing gateway
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag
* @see https://specs.ipfs.tech/http-gateways/path-gateway/#etag-response-header
*/
export function getETag({ cid, reqFormat, weak, rangeStart, rangeEnd, contentPrefix }) {
const prefix = getPrefix({ weak, reqFormat });
let suffix = getFormatSuffix({ reqFormat });
if (rangeStart != null || rangeEnd != null) {
suffix += `.${rangeStart ?? '0'}-${rangeEnd ?? 'N'}`;
}
return `${prefix}"${contentPrefix ?? ''}${cid.toString()}${suffix}"`;
}
//# sourceMappingURL=get-e-tag.js.map