import { sha256base58 } from '@basemaps/config';
import { HttpHeader } from '@linzjs/lambda';
export const Etag = {
    key(obj) {
        if (Buffer.isBuffer(obj) || typeof obj === 'string')
            return sha256base58(obj);
        return sha256base58(JSON.stringify(obj));
    },
    isNotModified(req, cacheKey) {
        // If the user has supplied a IfNoneMatch Header and it contains the full sha256 sum for our
        // etag this tile has not been modified.
        const ifNoneMatch = req.header(HttpHeader.IfNoneMatch);
        if (ifNoneMatch != null && ifNoneMatch.indexOf(cacheKey) > -1) {
            req.set('cache', { hit: true, match: ifNoneMatch });
            return true;
        }
        return false;
    },
};
//# sourceMappingURL=etag.js.map