Module openflax.handler.file

Plain file-serving handler for OpenFlax.

Behaviour: openflax.handler.

Description

Plain file-serving handler for OpenFlax.

This handler serves plain files from a specified "document root" directory. It takes some measures to ensure that it cannot serve files from anywhere outside that directory (with the notable exception of symbolic and hard links.)

This handler supports the following configuration options in the conf() passed to it:

Function Index

document/1Derives the name of the document (fully-qualified filename) from the cfg_document_root and sreq_basic_resource settings in the given conf().
fold_files/3Folds the function Fun(F, IsDir, Acc) -> {Recurse, Acc1} over all files F in Dir that match the regular expression RegExp.
is_accessible/2Reports whether the file named by the specified fully-qualified filename is accessible to the web server.
is_binary/1Makes an educated guess as to whether the file is binary (as opposed to plain ASCII text).
is_world_executable/1Checks whether a file is executable by the entire world.
is_world_readable/1Checks whether a file is readable by the entire world.
is_world_writeable/1Checks whether a file is writeable by the entire world.
serve/1Serves a file from the filesystem to the connected user agent.
start/1Initializes the file-serving handler.
stop/1Shuts down the file-serving handler.

Function Details

document/1

document(Conf::conf()) -> filename()

Derives the name of the document (fully-qualified filename) from the cfg_document_root and sreq_basic_resource settings in the given conf(). The returned filename is not flattened.

fold_files/3

fold_files(Dir::string(), Fun::fun(), Acc::term()) -> term()

Folds the function Fun(F, IsDir, Acc) -> {Recurse, Acc1} over all files F in Dir that match the regular expression RegExp. If Recursive is true all sub-directories of F are processed. (This function is a modified version of the function of the same name in filelib.erl.)

is_accessible/2

is_accessible(FileName::filename(), Conf::conf()) -> true | false

Reports whether the file named by the specified fully-qualified filename is accessible to the web server.

is_binary/1

is_binary(Filename::filename()) -> true | false | {error, Reason}

Makes an educated guess as to whether the file is binary (as opposed to plain ASCII text). The heuristic used is similar to that of grep and Perl's -B operator. The first 32K of the file is examined for odd characters such as strange control codes or characters with the high bit set. If too many strange characters (>30%) are found, or if any zero bytes (nulls) are encountered, the file is considered binary.

is_world_executable/1

is_world_executable(Filename::filename()) -> true | false

Checks whether a file is executable by the entire world.

is_world_readable/1

is_world_readable(Filename::filename()) -> true | false

Checks whether a file is readable by the entire world.

is_world_writeable/1

is_world_writeable(Filename::filename()) -> true | false

Checks whether a file is writeable by the entire world.

serve/1

serve(Conf::conf()) -> {response(), conf()}

Serves a file from the filesystem to the connected user agent.

start/1

start(Conf::conf()) -> conf()

Initializes the file-serving handler.

stop/1

stop(Conf::conf()) -> conf()

Shuts down the file-serving handler.