Behaviour: openflax.handler.
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:
cfg_document_rootfilename().
The root directory, from which to serve files. Note that this setting
is used by several handlers, and as such, it must be defined outside
any specific handler (in the openflax section, or in
one of the virtual hosts.)
cfg_file_options[option()].
Options to pass to file:open/2. These are tweakable
for maximizing performance. A typical set would be
[raw, read_ahead, binary].
cfg_file_chunk_sizeinteger().
Number of bytes per chunk of file sent to the HTTP client. This is
tweakable for maximizing performance. A typical value would be
16384.
| document/1 | Derives the name of the document (fully-qualified filename)
from the cfg_document_root and sreq_basic_resource
settings in the given conf(). |
| fold_files/3 | Folds the function Fun(F, IsDir, Acc) -> {Recurse, Acc1} over all files F in Dir that match the regular expression RegExp. |
| is_accessible/2 | Reports whether the file named by the specified fully-qualified filename is accessible to the web server. |
| is_binary/1 | Makes an educated guess as to whether the file is binary (as opposed to plain ASCII text). |
| is_world_executable/1 | Checks whether a file is executable by the entire world. |
| is_world_readable/1 | Checks whether a file is readable by the entire world. |
| is_world_writeable/1 | Checks whether a file is writeable by the entire world. |
| serve/1 | Serves a file from the filesystem to the connected user agent. |
| start/1 | Initializes the file-serving handler. |
| stop/1 | Shuts down the file-serving handler. |
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(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(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(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(Filename::filename()) -> true | false
Checks whether a file is executable by the entire world.
is_world_readable(Filename::filename()) -> true | false
Checks whether a file is readable by the entire world.
is_world_writeable(Filename::filename()) -> true | false
Checks whether a file is writeable by the entire world.
serve(Conf::conf()) -> {response(), conf()}
Serves a file from the filesystem to the connected user agent.
Initializes the file-serving handler.
Shuts down the file-serving handler.