/**
 * We use strong Etags for immutable responses and weak ones (prefixed with W/ )
 * for mutable/generated ones (ipns, car, tar, and generated HTML).
 *
 * Block and car responses should have different etags to deserialized ones, so
 * you can add a prefix like we do in the 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, contentType, ranges, contentPrefix }) {
    const prefix = contentType.immutable ? '' : 'W/';
    let suffix = contentType.etag;
    if (ranges?.length != null && ranges?.length > 0) {
        const validRanges = ranges
            .filter(range => range.start != null || range.end != null);
        if (validRanges.length > 0) {
            suffix += '.' + validRanges
                .map(range => `${range.start ?? 0}-${range.end ?? 'N'}`)
                .join(',');
        }
    }
    return `${prefix}"${contentPrefix ?? ''}${cid.toString()}${suffix}"`;
}
export function ifNoneMatches(etag, headers) {
    const ifNoneMatch = (headers?.get('if-none-match') ?? '')
        .split(',')
        .map(tag => {
        tag = tag.trim();
        if (tag.startsWith('W/')) {
            tag = tag.substring(2);
        }
        return tag;
    });
    if (etag.startsWith('W/')) {
        etag = etag.substring(2);
    }
    return ifNoneMatch.includes('*') || ifNoneMatch.includes(etag);
}
//# sourceMappingURL=get-e-tag.js.map