File
Blob: src/worker/dav/etag.ts
| 1 | import { randomHex } from "@/worker/auth/bytes"; |
| 2 | |
| 3 | export function generateEtag(): string { |
| 4 | return `"${randomHex(16)}"`; |
| 5 | } |
| 6 | |
| 7 | export function strongEtagMatches(headerValue: string, etag: string | null): boolean { |
| 8 | if (!etag) return false; |
| 9 | return headerValue |
| 10 | .split(",") |
| 11 | .map((part) => part.trim()) |
| 12 | .some((part) => part === etag || part === "*"); |
| 13 | } |
| 14 | |
| 15 | export function ifNoneMatchBlocks(headerValue: string, etag: string | null): boolean { |
| 16 | return headerValue |
| 17 | .split(",") |
| 18 | .map((part) => part.trim()) |
| 19 | .some((part) => part === "*" || (etag !== null && part === etag)); |
| 20 | } |