Handler to manage static content.
This is a US-Web custom, derived version of cowboy_static.erl, modified (mostly stripped-down) in order to comply with the conventions of Universal Server and to support 404 errors and logging.
Table-based states could have been used, this could have even been a WOOPER instance per request, however we went for the least overhead and for direct map management.
As done by Cowboy, exactly one process is spawned per request.access_type() = direct | archive
bin_content_path() = us_web_handler:bin_content_path()
extra() = [extra_charset() | extra_etag() | extra_mimetypes()]
extra_charset() = {charset, module(), function()} | {charset, binary()}
extra_etag() = {etag, module(), function()} | {etag, false}
extra_mimetypes() = {mimetypes, module(), function()} | {mimetypes, binary() | {binary(), binary(), [{binary(), binary()}]}}
file_info() = file_utils:file_info()
handler_return() = us_web_handler:handler_return()
handler_state() = us_web_handler:handler_state()
opts() = {file | dir, ustring() | binary()} | {file | dir, ustring() | binary(), extra()} | {priv_file | priv_dir, atom(), ustring() | binary()} | {priv_file | priv_dir, atom(), ustring() | binary(), extra()}
rest_handler_state() = {bin_content_path(), {access_type(), file_info()} | basic_utils:error_term(), extra()}
State for the cowboy_rest handler.
ustring() = text_utils:ustring()
charsets_provided/2 | Detects the charset of the file. |
content_types_provided/2 | Detects the mimetype of the file. |
forbidden/2 | Forbids relevant content. |
generate_etag/2 | Generates an etag for the handler-referenced file. |
get_file/2 | Streams the handler-referenced file. |
init/2 | Resolves the file that will be sent, and gets its file information. |
last_modified/2 | Returns the time of last modification of the handler-referenced file. |
malformed_request/2 | Rejects requests that tried to access a file outside the target directory, or used reserved characters. |
ranges_provided/2 | Enables support for range requests. |
resource_exists/2 | Assumes the resource does not exist if it is not a regular file. |
Detects the charset of the file.
content_types_provided(Req, State) -> {[{binary(), get_file}], Req, State}
State = rest_handler_state()
Detects the mimetype of the file.
Forbids relevant content.
Directories, files that cannot be accessed at all, and files with no read flag are forbidden.Generates an etag for the handler-referenced file.
get_file(Req::cowboy_req:req(), HState::rest_handler_state()) -> {{sendfile, 0, non_neg_integer(), binary()}, cowboy_req:req(), rest_handler_state()}
Streams the handler-referenced file.
init(Req::cowboy_req:req(), HState::handler_state()) -> handler_return()
Resolves the file that will be sent, and gets its file information.
If the handler is configured to manage a directory, checks that the requested file is inside the configured directory.last_modified(Req::cowboy_req:req(), HState::rest_handler_state()) -> {calendar:datetime(), cowboy_req:req(), rest_handler_state()}
Returns the time of last modification of the handler-referenced file.
malformed_request(Req, State) -> {boolean(), Req, State}
Rejects requests that tried to access a file outside the target directory, or used reserved characters.
Enables support for range requests.
Assumes the resource does not exist if it is not a regular file.
Generated by EDoc