/*! * Adapted from koa-send at https://github.com/koajs/send and which is licensed * with the MIT license. */ import type { Context } from "./context.js"; /** Options which can be specified when using the {@linkcode send} * middleware. */ export interface SendOptions { /** Try to serve the brotli version of a file automatically when brotli is * supported by a client and if the requested file with `.br` extension * exists. (defaults to `true`) */ brotli?: boolean; /** A record of extensions and content types that should be used when * determining the content of a file being served. By default, the * [`media_type`](https://github.com/oakserver/media_types/) database is used * to map an extension to the served content-type. The keys of the map are * extensions, and values are the content types to use. The content type can * be a partial content type, which will be resolved to a full content type * header. * * Any extensions matched will override the default behavior. Key should * include the leading dot (e.g. `.ext` instead of just `ext`). * * ### Example * * ```ts * app.use((ctx) => { * return send(ctx, ctx.request.url.pathname, { * contentTypes: { * ".importmap": "application/importmap+json" * }, * root: ".", * }) * }); * ``` */ contentTypes?: Record; /** Try to match extensions from passed array to search for file when no * extension is sufficed in URL. First found is served. (defaults to * `undefined`) */ extensions?: string[]; /** If `true`, format the path to serve static file servers and not require a * trailing slash for directories, so that you can do both `/directory` and * `/directory/`. (defaults to `true`) */ format?: boolean; /** Try to serve the gzipped version of a file automatically when gzip is * supported by a client and if the requested file with `.gz` extension * exists. (defaults to `true`). */ gzip?: boolean; /** Allow transfer of hidden files. (defaults to `false`) */ hidden?: boolean; /** Tell the browser the resource is immutable and can be cached * indefinitely. (defaults to `false`) */ immutable?: boolean; /** Name of the index file to serve automatically when visiting the root * location. (defaults to none) */ index?: string; /** Browser cache max-age in milliseconds. (defaults to `0`) */ maxage?: number; /** A size in bytes where if the file is less than this size, the file will * be read into memory by send instead of returning a file handle. Files less * than the byte size will send an "strong" `ETag` header while those larger * than the bytes size will only be able to send a "weak" `ETag` header (as * they cannot hash the contents of the file). (defaults to 1MiB) */ maxbuffer?: number; /** Root directory to restrict file access. */ root: string; } /** Asynchronously fulfill a response with a file from the local file * system. * * Requires Deno read permission for the `root` directory. */ export declare function send({ request, response }: Context, path: string, options?: SendOptions): Promise;