Module us_web_static

Handler to manage static content.

Description

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.

Data Types

access_type()

access_type() = direct | archive

bin_content_path()

bin_content_path() = us_web_handler:bin_content_path()

extra()

extra() = [extra_charset() | extra_etag() | extra_mimetypes()]

extra_charset()

extra_charset() = {charset, module(), function()} | {charset, binary()}

extra_etag()

extra_etag() = {etag, module(), function()} | {etag, false}

extra_mimetypes()

extra_mimetypes() = {mimetypes, module(), function()} | {mimetypes, binary() | {binary(), binary(), [{binary(), binary()}]}}

file_info()

file_info() = file_utils:file_info()

handler_return()

handler_return() = us_web_handler:handler_return()

handler_state()

handler_state() = us_web_handler:handler_state()

opts()

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()

rest_handler_state() = {bin_content_path(), {access_type(), file_info()} | basic_utils:error_term(), extra()}

State for the cowboy_rest handler.

ustring()

ustring() = text_utils:ustring()

Function Index

charsets_provided/2Detects the charset of the file.
content_types_provided/2Detects the mimetype of the file.
forbidden/2Forbids relevant content.
generate_etag/2Generates an etag for the handler-referenced file.
get_file/2Streams the handler-referenced file.
init/2Resolves the file that will be sent, and gets its file information.
last_modified/2Returns the time of last modification of the handler-referenced file.
malformed_request/2Rejects requests that tried to access a file outside the target directory, or used reserved characters.
ranges_provided/2Enables support for range requests.
resource_exists/2Assumes the resource does not exist if it is not a regular file.

Function Details

charsets_provided/2

charsets_provided(Req, State) -> {[binary()], Req, State}

Detects the charset of the file.

content_types_provided/2

content_types_provided(Req, State) -> {[{binary(), get_file}], Req, State}

Detects the mimetype of the file.

forbidden/2

forbidden(Req, State) -> {boolean(), Req, State}

Forbids relevant content.

Directories, files that cannot be accessed at all, and files with no read flag are forbidden.

generate_etag/2

generate_etag(Req, State) -> {{strong | weak, binary()}, Req, State}

Generates an etag for the handler-referenced file.

get_file/2

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/2

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/2

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/2

malformed_request(Req, State) -> {boolean(), Req, State}

Rejects requests that tried to access a file outside the target directory, or used reserved characters.

ranges_provided/2

ranges_provided(Req, State) -> {[{binary(), auto}], Req, State}

Enables support for range requests.

resource_exists/2

resource_exists(Req, State) -> {boolean(), Req, State}

Assumes the resource does not exist if it is not a regular file.


Generated by EDoc