[http]
http
[http] configures every response the server sends. It sets the security headers, the response to a cross-origin call, the defaults of every cookie, and how much an error page shows. A cross-origin call is a call from a web page on another site. CORS (Cross-Origin Resource Sharing) is the set of headers that allows such a call.
With nothing written, every value is the safest choice. The security headers are on. Cross-origin calls are not allowed until you name the allowed origins. Cookies are Secure, HttpOnly and SameSite=Lax. An error page says only that something went wrong.
A program may change most of these values with Core\Config::set. The change applies only to the response of the request it is handling. The next request uses the values from the file again.
The page of Core\Config::set lists the settings a program may change. Core\Config::set returns false for every other setting, such as these:
http.csrf_keyandhttp.csrf_key_file, the key that signs cross-site request tokens.http.errors.detail, because the error page is sent before the program starts.http.cors.methods,http.cors.headersandhttp.cors.max_age. Only the response to a CORS preflight request uses them. The server sends that response before any program runs.
A request may change these keys in this block with Core\Config::set: headers.content_type_options, headers.frame_ancestors, headers.referrer_policy, headers.hsts, headers.hsts_subdomains, headers.content_security_policy, headers.permissions_policy, cors.origins, cors.expose, cors.credentials, cookies.secure, cookies.http_only, cookies.same_site, cookies.path, client.connect_timeout, client.deadline, client.max_redirects, client.idle, client.max_duration, client.socket.max_message, client.socket.send_timeout. Only nvs.toml sets the others.
A change in the file takes effect a few seconds after you save it. The server does not restart.
What a response is shaped by
<?nvs// `[http]` configures every response: security headers, cross-origin calls, cookie// defaults and how much an error page shows. This file sets nothing, so each value// is the built-in default. Each default is the safest choice, like this one://// [http.errors]// detail = "generic"
echo 'error detail: ', Core\Config::get('http.errors.detail') ?? '(no value)', "\n";echo 'cookies default: ', Core\Config::get('http.cookies.same_site') ?? '(no value)', "\n";echo 'CORS origins: ', Core\Config::get('http.cors.origins') ?? '(nothing, so no cross-origin call is answered)', "\n";
// A program may change these values for the request it is handling. The next request// uses the values from the file again. This prints `yes` and then `Strict`.echo 'stricter: ', Core\Config::set('http.cookies.same_site', 'Strict') ? 'yes' : 'no', "\n";echo 'now in force: ', Core\Config::get('http.cookies.same_site') ?? '(nothing)', "\n";
// The error page is shown before the program starts, so a program cannot change it.// This prints `no`.string $detail = 'http.errors.detail';echo 'say more: ', Core\Config::set($detail, 'full') ? 'yes' : 'no', "\n";
// A program cannot change `http.csrf_key`, the secret key that signs cross-site request// tokens. With that key, a request could sign its own tokens. This prints `no`.string $key = 'http.csrf_key';echo 'choose the key: ', Core\Config::set($key, 'whatever-i-like') ? 'yes' : 'no', "\n";
// `Core\Config::restore` deletes the value this program set. The file does not set// this value, so `get` returns the default again. This prints `Lax`.Core\Config::restore('http.cookies.same_site');echo 'restored to: ', Core\Config::get('http.cookies.same_site') ?? '(no value)', "\n";error detail: genericcookies default: LaxCORS origins: (nothing, so no cross-origin call is answered)stricter: yesnow in force: Strictsay more: nochoose the key: norestored to: LaxChangelog
| Version | Change |
|---|---|
0.0.6 | The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change. |
http.csrf_key
The key the server checks every CSRF token against. Naming it is what turns the token half of the check on.
Novis refuses a state-changing request whose Origin names somewhere other than where it arrived, and it does that with nothing configured at all. What it cannot refuse until this key is named is a covered request that brought no Origin — which is every non-browser client, and so every API caller: with no key there is no token this deployment ever issued for such a request to be missing. Name the key and those requests are covered too.
The key is the operator's alone. Every request is checked against this one value, so a program that could write it would be choosing which forgeries the requests beside it accept. A rotated key governs the next request rather than the next restart, and a key the door cannot read is refused at startup rather than left quietly unarmed. csrf_key_file is the same value read out of a file, which is the spelling an audited deployment uses.
Only nvs.toml sets this key. A request may not change it.
A change in the file takes effect a few seconds after you save it. The server does not restart.
The key the door checks every token against
<?nvs// `[http] csrf_key` is the key the server uses to check the CSRF token of a request.// The server checks tokens only when this key is set. This file sets no key,// so no request needs a token yet.
// The key is a secret, so your program cannot print it. This line checks whether a key is set.echo 'door key: ', Core\Config::get('http.csrf_key') == null ? '(nothing, so no token is expected yet)' : '(a key is set)', "\n";echo 'read from file: ', Core\Config::get('http.csrf_key_file') ?? '(nothing)', "\n";
// The server checks every request against this one key, so a program cannot set it.// A program that could set it could make forged requests pass. Both lines print `no`.string $key = 'http.csrf_key';string $file = 'http.csrf_key_file';echo 'name one here: ', Core\Config::set($key, 'a-key-of-my-own') ? 'yes' : 'no', "\n";echo 'or name a file: ', Core\Config::set($file, '/tmp/csrf.key') ? 'yes' : 'no', "\n";
// Without the key, the server still rejects a browser request whose `Origin` header names// another site. A request with no `Origin` header is checked only when the key is set.
// A program can also make its own tokens with its own key. `Core\Csrf::issue` makes a token// for one session, and `Core\Csrf::verify` accepts it only for that session.secret bytes $mine = Core\Crypto::generateKey();string $token = Core\Csrf::issue('sid-ada', $mine);echo 'own token: ', Core\Csrf::verify($token, 'sid-ada', $mine) ? 'accepted' : 'refused', "\n";echo 'other session: ', Core\Csrf::verify($token, 'sid-bob', $mine) ? 'accepted' : 'refused', "\n";door key: (nothing, so no token is expected yet)read from file: (nothing)name one here: noor name a file: noown token: acceptedother session: refusedChangelog
| Version | Change |
|---|---|
0.0.6 | The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change. |
http.csrf_key_file
The door's CSRF key written as a path instead of a value: the file's content is the key.
This is the spelling a deployment uses when something else issues the key — a secret manager, or an orchestrator mounting a file into the container — so the key never sits in a configuration file that gets committed and shared. The file's whole content is the value, with one trailing newline removed and nothing else trimmed, so a key written by one tool is the same key when another tool wrote it. A program then asks for csrf_key and receives the content; nothing asks for the path.
Exactly one of the pair may be written. Both together is refused when the server starts, because one value with two sources is a question about which wins that nobody should have to ask. The file is checked like every other configuration input: an account other than the server's that can rewrite it would be choosing the key, so the server refuses to start rather than believing it. A file that is merely readable by others is warned about and read.
Only nvs.toml sets this key. A request may not change it.
A change in the file takes effect a few seconds after you save it. The server does not restart.
The door key read out of a file
<?nvs// `[http] csrf_key_file` is the path of a file that contains the CSRF key of the server.// Use it when another tool makes the key, such as a secret manager. Then the key is never// in a configuration file that you commit. This file sets neither `csrf_key` nor `csrf_key_file`.
echo 'key from a file: ', Core\Config::get('http.csrf_key_file') ?? '(nothing)', "\n";
// When a file is set, `get('http.csrf_key')` returns the content of the file, never the path.// One newline at the end is removed. The key is a secret, so this line only checks whether it is set.echo 'key in force: ', Core\Config::get('http.csrf_key') == null ? '(nothing, so no token is expected yet)' : '(a key is set)', "\n";
// The server checks every request against this one key, so a program cannot set the key// or the file. Both calls return `false`, and the key is still not set.string $file = 'http.csrf_key_file';string $key = 'http.csrf_key';echo 'name a file: ', Core\Config::set($file, '/tmp/csrf.key') ? 'yes' : 'no', "\n";echo 'or the key: ', Core\Config::set($key, 'a-key-of-my-own') ? 'yes' : 'no', "\n";echo 'still in force: ', Core\Config::get('http.csrf_key') == null ? '(nothing)' : '(a key is set)', "\n";
// The server does not start if both `csrf_key` and `csrf_key_file` are set. It also does// not start if an account other than the server's account can change the key file.key from a file: (nothing)key in force: (nothing, so no token is expected yet)name a file: noor the key: nostill in force: (nothing)Changelog
| Version | Change |
|---|---|
0.0.6 | The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change. |
http.client.pool_idle
How many outbound connections one core keeps open between calls, ready for the next one.
Opening a connection to an upstream API costs a round trip, and a TLS handshake on top of that, so a connection that has finished its call is kept rather than closed. The ones being kept are idle: they hold a socket and a buffer and are doing no work. This is how many of them a single core will hold on to, which makes it a decision about the size of the machine — a host with sixteen cores holds up to sixteen times this number.
In plain words: it is the size of the shelf that finished connections are put back on, per core. A bigger shelf means fewer handshakes and more memory sitting idle; 0 means the shelf is taken away and every call opens its own connection.
Because the shelf belongs to the core and outlives the request that filled it, a program may read this number and never raise it. A request that could would be spending memory that every other request on that core then goes without.
Only nvs.toml sets this key. A request may not change it.
A change in the file takes effect a few seconds after you save it. The server does not restart.
The examples below run with this configuration file.
# Each core keeps at most 16 finished connections open for the next call.[http.client]pool_idle = 16How many finished connections a core keeps
<?nvs// After a call finishes, its connection stays open. The next call to the same server// then needs no new connection and no new TLS handshake. `[http.client] pool_idle` is// how many of these open connections one core keeps. This file sets it://// [http.client]// pool_idle = 16
echo 'idle connections per core: ', Core\Config::get('http.client.pool_idle') ?? '(no value)', "\n";
// Each core keeps its own connections. A host with 16 cores keeps up to 16 times// this number, so this prints `256`.echo 'so a 16-core host holds: ', 16 * 16, "\n";
// The right number depends on the size of the machine, so a program cannot change it.// `Core\Config::set` returns `false`, so this prints `no`.string $name = 'http.client.pool_idle';echo 'raise it from code: ', Core\Config::set($name, '512') ? 'yes' : 'no', "\n";
// A program may change the settings in this block that affect only its own call.// `http.client.deadline` is one of them, so this prints `yes` and then `2s`.echo 'shorten my own call: ', Core\Config::set('http.client.deadline', '2s') ? 'yes' : 'no', "\n";echo 'now in force: ', Core\Config::get('http.client.deadline') ?? '(nothing)', "\n";
// `Core\Config::restore` deletes the value this program set. This file sets no// deadline, so `get` returns the default, `30s`.Core\Config::restore('http.client.deadline');echo 'back to the file: ', Core\Config::get('http.client.deadline') ?? '(no value)', "\n";idle connections per core: 16so a 16-core host holds: 256raise it from code: noshorten my own call: yesnow in force: 2sback to the file: 30sChangelog
| Version | Change |
|---|---|
0.0.6 | The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change. |
http.client.pool_idle_timeout
How long an unused outbound HTTP connection stays open before Novis closes it.
After a call finishes, Novis keeps the connection open, so the next call to the same server can use it and does not need to connect again. Servers, proxies and load balancers close connections that are unused for some time, and they do not announce it. A call on such a connection fails and must be sent again. This setting closes an unused connection before the other side does.
[http.client] pool_idle is how many unused connections are kept. pool_idle_timeout is how long each one is kept. The default is 30 seconds, which is shorter than the idle timeout of common proxies. A value with no unit is in seconds, so 30 and "30s" are the same.
Good to know: a kept connection is used by many requests, so a program can read this setting and cannot change it.
The example prints both settings and then tries to change the timeout. Core\Config::set returns false.
Only nvs.toml sets this key. A request may not change it.
A change in the file takes effect a few seconds after you save it. The server does not restart.
The examples below run with this configuration file.
# Each core keeps at most 16 finished connections open.# A kept connection is closed after 30 seconds without use.[http.client]pool_idle = 16pool_idle_timeout = "30s"How long a kept connection may sit unused
<?nvs// After a call, the connection stays open for the next call. The other server closes unused// connections and does not say so. `[http.client] pool_idle_timeout` is how long a// connection may stay unused before Novis closes it first. This file sets both values://// [http.client]// pool_idle = 16// pool_idle_timeout = "30s"
echo 'how many may be kept: ', Core\Config::get('http.client.pool_idle') ?? '(no value)', "\n";echo 'how long one may sit: ', Core\Config::get('http.client.pool_idle_timeout') ?? '(no value)', "\n";
// `Core\Time\Duration::parse` reads the timeout as a duration. This prints `30 seconds`. Without// a timeout, a connection the other server closed stays open here, and the next call on it fails.Core\Time\Duration $window = Core\Time\Duration::parse(Core\Config::get('http.client.pool_idle_timeout') ?? '30s');echo 'which is: ', $window->toSeconds(), " seconds\n";
// A duration with no unit is in seconds, so `30` and `"30s"` are the same. `pool_idle`// is a count and takes no unit. This prints `30000`.echo 'and in milliseconds: ', $window->toMilliseconds(), "\n";
// Many requests use these connections, so a program cannot change either setting.// `Core\Config::set` returns `false`, and the timeout is still `30s`.string $name = 'http.client.pool_idle_timeout';echo 'hold them longer: ', Core\Config::set($name, '24h') ? 'yes' : 'no', "\n";echo 'still in force: ', Core\Config::get('http.client.pool_idle_timeout') ?? '(nothing)', "\n";how many may be kept: 16how long one may sit: 30swhich is: 30 secondsand in milliseconds: 30000hold them longer: nostill in force: 30sChangelog
| Version | Change |
|---|---|
0.0.6 | The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change. |
http.client.proxy
The forward proxy that every outbound HTTP call uses. Only the configuration file can set it.
When the [http.client.proxy] block is in the configuration file, calls use that proxy. When the block is missing, no proxy is used. There is no proxy option for a single call. Novis also does not read HTTP_PROXY, HTTPS_PROXY or NO_PROXY from the environment.
url is the proxy. resolve says whether Novis or the proxy looks up the destination host. bypass lists the hosts that are reached without the proxy. username, password and password_file are the login for the proxy.
Novis checks the address of every outbound call before it connects. A proxy makes the connection for Novis, so the person who runs the server must choose it. A program that could choose a proxy could avoid that check.
The example reads the keys and tries to set each one. Core\Config::set returns false every time.
Only nvs.toml sets this key. A request may not change it.
A change in the file takes effect a few seconds after you save it. The server does not restart.
Where an outbound call leaves from
<?nvs// `[http.client.proxy]` is the forward proxy that outbound calls use. Only the configuration// file can set it. This file has no such block, so no proxy is used.
echo 'proxy: ', Core\Config::get('http.client.proxy.url') ?? '(no block, so no proxy at all)', "\n";echo 'who resolves: ', Core\Config::get('http.client.proxy.resolve') ?? '(nothing — the block has no default for it)', "\n";echo 'reached direct: ', Core\Config::get('http.client.proxy.bypass') ?? '(nothing — with no proxy there is nothing to go around)', "\n";
// A program cannot set a proxy, so both lines print `no`. Novis checks the address// of every outbound call, and a proxy chosen by a program could avoid that check.string $url = 'http.client.proxy.url';string $resolve = 'http.client.proxy.resolve';echo 'point it at me: ', Core\Config::set($url, 'http://somewhere-else.test:8080') ? 'yes' : 'no', "\n";echo 'let it resolve: ', Core\Config::set($resolve, 'proxy') ? 'yes' : 'no', "\n";
// Novis does not read proxy settings from environment variables such as `HTTPS_PROXY`.// Every request shares them, and no configuration file records them.echo 'HTTPS_PROXY: ', Core\Env::get('HTTPS_PROXY') ?? '(unset here, and it would change nothing either way)', "\n";
// A program cannot set any key of the block, including the password.// `Core\Config::set` returns `false` for each one, so every line prints `no`.array<string> $keys = ['url', 'resolve', 'bypass', 'username', 'password', 'password_file'];foreach ($keys as string $key) { echo 'writable by me: ', $key, ' -> ', Core\Config::set('http.client.proxy.' . $key, 'anything') ? 'yes' : 'no', "\n";}proxy: (no block, so no proxy at all)who resolves: (nothing — the block has no default for it)reached direct: (nothing — with no proxy there is nothing to go around)point it at me: nolet it resolve: noHTTPS_PROXY: (unset here, and it would change nothing either way)writable by me: url -> nowritable by me: resolve -> nowritable by me: bypass -> nowritable by me: username -> nowritable by me: password -> nowritable by me: password_file -> noChangelog
| Version | Change |
|---|---|
0.0.6 | The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change. |
http.client.socket
The two bounds an outbound WebSocket has that no other outbound call does: the largest message it will put back together, and how long one frame may wait to be written.
A WebSocket stays open and delivers messages that arrive in pieces, so the receiving side has to hold the pieces until the last one lands. The message cap is how large that may get before the socket is closed instead — without it, a peer decides how much memory the task holding the socket uses. The send timeout is the other direction: how long a frame may wait for a peer that has stopped reading before the send fails.
Neither has a spelling that means "no limit". Both false and zero are refused where the configuration is read, so a socket that waits forever or grows without end is not something this file can ask for.
Unlike the rest of [http.client], these two are a program's to change. Each bounds the one socket the program opened, and neither spends anything another request then goes without — so a program that knows its own peer names its own value at the call instead.
A request may change these keys in this block with Core\Config::set: max_message, send_timeout. Only nvs.toml sets the others.
A change in the file takes effect a few seconds after you save it. The server does not restart.
The two bounds an outbound socket has
<?nvs// `[http.client.socket]` sets two limits for an outbound WebSocket: the largest message it// accepts, and how long one frame may wait to be sent. This file sets neither, so both use// the built-in default: 4 MiB and 30 seconds. Incoming WebSockets use the same values.
echo 'largest message: ', Core\Config::get('http.client.socket.max_message') ?? '(no value)', "\n";echo 'frame may wait: ', Core\Config::get('http.client.socket.send_timeout') ?? '(no value)', "\n";
// A program may change these two settings, because they affect only the socket it opened.// This prints `yes` and then `65536`.echo 'hold less: ', Core\Config::set('http.client.socket.max_message', '65536') ? 'yes' : 'no', "\n";echo 'now in force: ', Core\Config::get('http.client.socket.max_message') ?? '(nothing)', "\n";
// A program cannot change the pool or the proxy, so both lines print `no`. The pool uses// memory after this request ends, and the proxy affects every outbound call.string $pool = 'http.client.pool_idle';string $proxy = 'http.client.proxy.url';echo 'resize the pool: ', Core\Config::set($pool, '512') ? 'yes' : 'no', "\n";echo 'name a proxy: ', Core\Config::set($proxy, 'http://somewhere-else.test:8080') ? 'yes' : 'no', "\n";
// `Core\Config::restore` deletes the value this program set, so the default applies again.// The configuration file cannot remove a limit either: `false` and `0` are not allowed.Core\Config::restore('http.client.socket.max_message');echo 'restored to: ', Core\Config::get('http.client.socket.max_message') ?? '(no value)', "\n";largest message: 4194304frame may wait: 30shold less: yesnow in force: 65536resize the pool: noname a proxy: norestored to: 4194304Changelog
| Version | Change |
|---|---|
0.0.6 | The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change. |
