export const DAV_XML = "application/xml; charset=utf-8"; export function davResponse(body: string | null, status: number, headers: HeadersInit = {}): Response { const responseHeaders = new Headers(headers); if (body !== null && !responseHeaders.has("content-type")) responseHeaders.set("content-type", DAV_XML); return new Response(body, { status, headers: responseHeaders }); } export function emptyResponse(status: number, headers: HeadersInit = {}): Response { return new Response(null, { status, headers }); } export function methodNotAllowed(allow: string): Response { return new Response("Method Not Allowed", { status: 405, headers: { Allow: allow } }); } export function unauthorizedDav(): Response { return new Response("Unauthorized", { status: 401, headers: { "WWW-Authenticate": 'Basic realm="dab"' }, }); } export function davError(status: number, message: string, headers: HeadersInit = {}): Response { return new Response(message, { status, headers }); } // RFC 4791 7.8 / RFC 6352 8.3: signal that the server truncated a query report // result set with a DAV:error body containing DAV:number-of-matches-within-limits. export function numberOfMatchesWithinLimitsError(): Response { const body = '' + ''; return davResponse(body, 403); } export function parseDepth(value: string | null, fallback: "0" | "1" | "infinity"): "0" | "1" | "infinity" | null { if (value === null || value === "") return fallback; const normalized = value.toLowerCase(); if (normalized === "0" || normalized === "1" || normalized === "infinity") return normalized; return null; }