Table of Contents

TStaticModule Class

HTTP server module that serves static files from a directory in the local file system.

Remarks

The module maps the path of each incoming request (relative to the module base URI) to a file under RootDir. It responds to GET and HEAD requests, setting the Content-Type header from the file extension and, optionally, a Last-Modified header. When the request maps to a directory, the module serves one of the configured IndexFiles or, depending on FolderUrlMode, redirects to the canonical URL. Requests that do not match a file result in a 404 response, and methods other than GET or HEAD result in a 405 response.

Syntax

Unit: Sparkle.Module.Static

TStaticModule = class(THttpServerModule);

Constructors

Name Description
Create Overloaded
Create(string)
Create(string, string)

Methods

Name Description
DefineContentType Sets the Content-Type header of the response based on the extension of the given file name, unless a content type has already been set.
FindContentType Returns the MIME content type associated with the extension of the given file name.
NeedsRedirect Determines whether a request URI that maps to a directory should be redirected to its canonical form according to the specified folder URL mode.

Properties

Name Description
FolderUrlMode Gets or sets the trailing-slash redirection policy applied to request URIs that map to a directory.
IndexFiles The list of index file names searched, in order, when a request maps to a directory.
LastModified Indicates whether a Last-Modified header, based on the file write time, is included in responses. Defaults to True.
RootDir Gets or sets the root directory in the file system from which static files are served.