Generic, Cowboy-compliant handler for US-Web.
This handler:
- provides static dispatches so that the (static) websites corresponding to the virtual hosts can be appropriately served; see the US-Web configuration file (e.g. priv/for-testing/us-web-for-tests.config), which holds the data relative to virtual hosts
- handles HTTP errors (notably 404 ones, thanks to a specifically-generated web page)
Note that this handler is mostly a library (a toolbox centralising helpers on behalf of the other handlers), knowing that its sole purpose as an handler is to act as a placeholder.bin_content_path() = file_utils:bin_file_path()
The (binary) path for a web content.
handler_module() = basic_utils:module_name()
Module to handle web content through dispatch rules (e.g. 'cowboy_rest').
handler_return() = {ok | handler_module(), cowboy_req:req(), handler_state() | error}
See https://ninenines.eu/docs/en/cowboy/2.9/manual/cowboy_handler/
.
handler_state() = maybe(map())
State carried by the process in charge of a request, for most handlers.
http_status_code() = web_utils:http_status_code()
us_handler_state() = handler_state()
A US-Web specialised handler, a map which may notably contain entries with following keys:
- css_path: file_utils:bin_file_path(), a path relative to the content root of the corresponding virtual host pointing to the default CSS file to be used (e.g. for the 404 page)
- image_404 :: file_utils:bin_file_path(), a path relative to the content root of the corresponding virtual host pointing to an image (e.g. PNG) to be used when generating a 404 error pageget_base_footer/0 | Returns a base HTML footer. |
get_header/3 | Returns a suitable document header. |
init/2 | Inits specified handler. |
manage_access_log/3 | Manages specified handler access log. |
manage_error_log/4 | Manages specified handler error log. |
return_404/3 | Returns a suitable term to notify the request initiator that a 404 error was triggered (meaning that the requested content could not be found). |
get_base_footer() -> any()
Returns a base HTML footer.
get_header(Title, MaybeBinCssFile, MaybeBinIconFile) -> any()
Returns a suitable document header.
init(Req::cowboy_req:req(), HandlerState::handler_state()) -> handler_return()
Inits specified handler.
Typically called because a dispatch rule mentioned that module as a (debug) handler.manage_access_log(HandlerReturn::handler_return(), HttpStatusCode::http_status_code(), HState::handler_state()) -> void()
Manages specified handler access log.
Access log facility offered to web handlers, taking advantage of the request-specific process in order to further parallelize their processing.manage_error_log(Error::basic_utils:error_reason(), Req::cowboy_req:req(), BinFullFilePath::bin_content_path(), HState::handler_state()) -> void()
Manages specified handler error log.
Error log facility offered to web handlers, taking advantage of the request-specific process in order to further parallelize their processing.return_404(Req::cowboy_req:req(), BinFullFilepath::bin_content_path(), HState::handler_state()) -> handler_return()
Returns a suitable term to notify the request initiator that a 404 error was triggered (meaning that the requested content could not be found).
Maybe this dynamic implementation could be too resource-demanding (prone to denial of service attack) and may be replaced with a static binary string (yet then copied to each per-request process), determined once for all.Generated by EDoc