It enhances the `server::Server::run_server_on_rt` and `server::Server::run_standalone` functions to support cancellation to shut down the server gracefully on demand as a complement to the termination signals handling in Linux/Unix systems.
The `Server::run_standalone` function now accepts an optional
`cancel` parameter to shut down the server gracefully on demand as
a complement to the termination signals handling in Linux/Unix systems.
Functions updated:
```rs
/// NOTE:
/// Now it will also handle server cancellation via the `cancel_recv` param in Linux/Unix systems
/// similar to what Windows does.
pub fn run_server_on_rt<F>(self, cancel_recv: Option<Receiver<()>>, cancel_fn: F) -> Result
/// NOTE:
/// Now it also accepts a `cancel` param to shut down the server in Linux/Unix systems
/// similar to what Windows does.
pub fn run_standalone(self, cancel: Option<Receiver<()>>) -> Result
```
* feat: `all` and `experimental` cargo feature flags
- the `all` will host all available features (`default`) plus the
`experimental`.
- the `experimental` will only hold unstable features like for example
`metrics` (as of writing)
* chore: enable the `all` cargo feature for freebsd
this feature also fixes#312
it just introduces fuzzing and micro-benchmark tests for the static files module. As a way to continue enhancing the performance and security of SWS in general. It is expected to be improved over time including other modules as well.
The SWS binaries for ppc64le (powerpc64le-unknown-linux-gnu) and
s590x (s390x-unknown-linux-gnu) are dynamically linked so
it does **not** make so much sense to deliver them with either the
Alpine (musl) or the Scratch images (they even do not work properly as
of writing).
So we remove those two from the SWS Alpine and Scratch Docker image
variants to avoid misunderstandings or future issues.
The Debian Docker image should be preferred instead, either linux/ppc64le
or linux/s390x respectively.
This resolves#308
* feat: Prometheus metrics endpoint at /metrics
Signed-off-by: Tom Plant <tom@tplant.com.au>
* fix: add `experimental` prefix to metrics arg, env var, and logs
Signed-off-by: Tom Plant <tom@tplant.com.au>
* fix: disable tokio-metrics-collector on Windows
Signed-off-by: Tom Plant <tom@tplant.com.au>
* chore: address feedback
* refactor: rename feature to `experimental-metrics` and add test
* fix: freebsd ci tests
* refactor: move dependencies to the unix target section
---------
Signed-off-by: Tom Plant <tom@tplant.com.au>
Co-authored-by: Jose Quintana <joseluisquintana20@gmail.com>
* feat: support for `Range` requests out of bounds
SWS will make sure to return only what's available in that case which
seems to be a very common behavior across web servers.
Previously exceeding the length of a file returning `416 Requested
Range Not Satisfiable`. Now it will return what's available.
```sh
$ curl -IH "Range: bytes=50-9000" http://localhost/index.html
\# HTTP/1.1 206 Partial Content
\# Server: nginx/1.25.3
\# Date: Sun, 28 Jan 2024 22:09:20 GMT
\# Content-Type: text/html
\# Content-Length: 486
\# Last-Modified: Mon, 02 Oct 2023 04:49:01 GMT
\# Connection: keep-alive
\# ETag: "651a4bbd-218"
\# Content-Range: bytes 50-535/536
```
it resolves#295 and relates to https://github.com/orgs/static-web-server/discussions/145
* fix: wrong glob brace expansion capture in url redirects/rewrites
now an url redirect (or rewrite) `source` that uses glob groups with
brace expansions like `**/{*}.{jpg,jpeg}` will works as expected:
```toml
[advanced]
[[advanced.redirects]]
source = "**/{*}.{jpg,jpeg}"
destination = "http://localhost/new-images/$2.$3"
kind = 302
```
* chore: url rewrites/redirects test cases
* feat: optional `host` uri support for URL redirects
which allows redirecting based on a host's incoming uri making it
possible to perform for example www to non-www redirects.
config example:
```toml
[advanced]
[[advanced.redirects]]
host = "127.0.0.1:4433"
source = "/{*}"
destination = "https://localhost:4433/$1"
kind = 301
```
* chore: add test cases