diff --git a/handlers/static.ts b/handlers/static.ts index ab19988..faa6a14 100644 --- a/handlers/static.ts +++ b/handlers/static.ts @@ -7,6 +7,7 @@ import * as fs from '@std/fs'; import * as path from '@std/path'; import * as media_types from '@std/media-types'; import { SERVER } from '../server.ts'; +import { getCookies } from '@std/http/cookie'; let PUT_PATHS_ALLOWED: string[] | undefined = undefined; let DELETE_PATHS_ALLOWED: string[] | undefined = undefined; @@ -17,7 +18,7 @@ export type HANDLER_METHOD = ( normalized_path: string, server: SERVER ) => Promise | Response | undefined; -export type PRECHECK = (request: Request) => Promise | Response | undefined; +export type PRECHECK = (request: Request, meta: Record) => Promise | Response | undefined; export const PRECHECKS: Partial> = {}; export const HANDLERS: Partial> = { HEAD: async (_request: Request, normalized_path: string, _server: SERVER): Promise => { @@ -295,8 +296,14 @@ export default async function handle_static_files(request: Request, server: SERV const prechecks: PRECHECK[] = PRECHECKS[method] ?? []; + const cookies: Record = getCookies(request.headers); + const query = Object.fromEntries(new URL(request.url).searchParams.entries()); + for await (const precheck of prechecks) { - const error_response: Response | undefined = await precheck(request); + const error_response: Response | undefined = await precheck(request, { + cookies, + query + }); if (error_response) { return error_response; }