csrf ?not_allowed_handler ?cookie_key ?secret () returns a middleware that enables CSRF protection for unsafe HTTP requests.
form_data_name is the name of the input element that is used to send the CSRF token. The default is csrf. It is recommended to use a <hidden> field in a <form>.
not_allowed_handler is used if an unsafe request does not pass the CSRF protection check. By default, not_allowed_handler returns an empty response with status 403.
cookie_key is the key in the cookie under which a CSRF token will be stored. By default, cookie_key has a __Host prefix to increase cookie security. One important consequence of this prefix is, that the cookie cannot be sent across unencrypted (HTTP) connections. You should only set this argument if you know what you are doing and aware of the consequences.
secret is the secret used to hash the CSRF cookie value with. By default, SIHL_SECRET is used.
Internally, the CSRF protection is implemented as the Double Submit Cookie approach.
error ?email_config ?reporter ?handler () returns a middleware that catches all exceptions and shows them.
By default, it logs the exception with the request details. The response is either `text/html` or `application/json`, depending on the `Content-Type` header of the request. If SIHL_ENV is `development`, a more detailed debugging page is shown which makes development easier. You can override the error page/JSON that is shown by providing a custom error handler error_handler.
Optional email configuration email_config can be specified, which is a tuple (sender, recipient, send_function). Exceptions that are caught will be sent per email to recipient where sender is the sender of the email. Pass in the send function of the Sihl email service or provide your own send_function. An email will only be sent if SIHL_ENV is `production`.
An optional custom reporter reporter can be defined. The middleware passes the stringified exception as first argument to the reporter callback. Use the reporter to implement custom error reporting.
val session : ?cookie_key:string ->?secret:string ->unit ->Rock.Middleware.t
session ?cookie_key ?secret () returns a middleware that reads and stores session values. The actual session values are stored in a signed cookie. Be aware of the limitations of this technique. Firstly, make sure that the session value does not exceed 4KB. Secondly, the client is able to read the session values. If you need to store a large amount of data, use the sihl-cache package and store the key in the session cookie.
cookie_key is the key of the session cookie. By default, the value is _session.
secret is a secret string that is used to sign cookies. By default SIHL_SECRET is used.