UNPKG

@teclone/r-server

Version:

A lightweight, extensible web-server with inbuilt routing-engine, static file server, file upload handler, request body parser, middleware support and lots more

56 lines (55 loc) 1.64 kB
/// <reference types="node" /> import type { RServerConfig } from '../@types'; import { IncomingHttpHeaders } from 'http'; import { ServerResponse } from './Response'; export declare class FileServer { private config; private rootDir; constructor(rootDir: string, config: RServerConfig); /** * streams a file to client */ private streamFile; /** * validates range request content. * @see https://tools.ietf.org/html/rfc7233 */ private validateRangeRequest; /** * check if file is modified */ private doesClientNeedContent; /** * computes and returns a files eTag */ private computeETag; /** * returns default response headers */ private getFileDefaultHeaders; /** * process file */ private process; /** * returns the directory's default document if any */ private getDefaultDocument; /** * validates the request method and returns the public file or directory path that * matches the request url */ private validateRequest; /** * serves a static file response back to the client */ serve(requestPath: string, requestMethod: string, requestHeaders: IncomingHttpHeaders, response: ServerResponse): Promise<boolean>; /** * serves server http error files. such as 504, 404, etc */ serveHttpErrorFile(errorStatusCode: number, response: ServerResponse): Promise<boolean>; /** * serves file intended for download to the client */ serveDownload(filePath: string, response: ServerResponse, filename?: string): Promise<boolean>; }