From 38f0ece5dba3ce0f74811fd0327b05a35438ef8b Mon Sep 17 00:00:00 2001 From: Jose Quintana Date: Sun, 22 Nov 2026 01:28:32 +0100 Subject: [PATCH] docs(v3): document v3.0.0-beta.4 changes Add an "IPv6-Only Host" page for the new `--ipv6-only` option and list it in the CLI, env, TOML and defaults references, the features table and the sidebar. The migration guide now points to it to keep `::` IPv6-only as in v2. The CORS page now says that `Origin` is appended to the `Vary` header and keeps values already set, such as `Accept` on automatic directory listings. --- .vitepress/config.v3.mts | 1 + src/v3/configuration/cli.md | 4 +++- src/v3/configuration/env.md | 6 +++++- src/v3/configuration/file.md | 1 + src/v3/defaults.md | 1 + src/v3/features/cors.md | 2 ++ src/v3/features/ipv6-only.md | 24 ++++++++++++++++++++++++ src/v3/index.md | 1 + src/v3/migration-guide.md | 4 ++-- 9 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 src/v3/features/ipv6-only.md diff --git a/.vitepress/config.v3.mts b/.vitepress/config.v3.mts index 2d91271..091dd1b 100644 --- a/.vitepress/config.v3.mts +++ b/.vitepress/config.v3.mts @@ -53,6 +53,7 @@ export const v3: DefaultTheme.Config = { { text: 'Idle Connection Timeout', link: '/v3/features/idle-timeout' }, { text: 'Maximum Connections', link: '/v3/features/max-connections' }, { text: 'Maximum Request Header Size', link: '/v3/features/max-header-size' }, + { text: 'IPv6-Only Host', link: '/v3/features/ipv6-only' }, { text: 'File Descriptor Socket Passing', link: '/v3/features/file-descriptor-socket-passing' }, { text: 'Unix Domain Socket', link: '/v3/features/unix-domain-socket' }, { text: 'Worker Threads Customization', link: '/v3/features/worker-threads' }, diff --git a/src/v3/configuration/cli.md b/src/v3/configuration/cli.md index 041c215..5273a08 100644 --- a/src/v3/configuration/cli.md +++ b/src/v3/configuration/cli.md @@ -19,7 +19,9 @@ Commands: Options: -a, --host - Host address (E.g 127.0.0.1 or ::1). The default `::` accepts both IPv6 and IPv4 connections where the OS supports dual-stack sockets [env: SERVER_HOST=] [default: ::] + Host address (E.g 127.0.0.1 or ::1). The default `::` accepts both IPv6 and IPv4 connections where the OS supports dual-stack sockets, unless `--ipv6-only` is enabled [env: SERVER_HOST=] [default: ::] + --ipv6-only [] + Make the unspecified IPv6 host `::` accept IPv6 connections only, leaving the port free for IPv4. It has no effect on a specific IPv6 host and cannot be used with an IPv4 host, `--fd` or `--unix-socket` [env: SERVER_IPV6_ONLY=] [default: false] [possible values: true, false] -p, --port Host port [env: SERVER_PORT=] [default: 8080] --open [] diff --git a/src/v3/configuration/env.md b/src/v3/configuration/env.md index 250c80b..11b9a9e 100644 --- a/src/v3/configuration/env.md +++ b/src/v3/configuration/env.md @@ -9,7 +9,11 @@ The server can be configured via the following environment variables. ## SERVER_HOST -Host address (e.g. `127.0.0.1` or `::1`). The default `::` accepts both IPv6 and IPv4 connections where the OS supports dual-stack sockets. Default `::`. +Host address (e.g. `127.0.0.1` or `::1`). The default `::` accepts both IPv6 and IPv4 connections where the OS supports dual-stack sockets, unless `SERVER_IPV6_ONLY` is enabled. Default `::`. + +## SERVER_IPV6_ONLY + +Make the unspecified IPv6 host `::` accept IPv6 connections only, leaving the port free for IPv4. It has no effect on a specific IPv6 host and cannot be used with an IPv4 host, `SERVER_LISTEN_FD` or `SERVER_UNIX_SOCKET`. See [IPv6-Only Host](../features/ipv6-only.md). Default `false` (disabled). ## SERVER_PORT diff --git a/src/v3/configuration/file.md b/src/v3/configuration/file.md index 28c1dd2..dfa09ee 100644 --- a/src/v3/configuration/file.md +++ b/src/v3/configuration/file.md @@ -21,6 +21,7 @@ Below is just an example showing all features with their default values. #### Address & Root dir host = "::" +ipv6-only = false port = 8080 root = "." diff --git a/src/v3/defaults.md b/src/v3/defaults.md index b9330fb..a19868e 100644 --- a/src/v3/defaults.md +++ b/src/v3/defaults.md @@ -26,6 +26,7 @@ When running `static-web-server` with no flags, you get: | Setting | Default | Rationale | | ----------------------- | --------------------------------- | -------------------------------------------------------------------------------- | | Host | `::` (all interfaces, dual-stack) | Reachable from any network interface, over IPv6 and IPv4 where the OS allows it. | +| IPv6 only | disabled | `::` also accepts IPv4 by default; `--ipv6-only` leaves the IPv4 port free. | | Port | `8080` | Non-privileged port, no `root` needed. | | Unix socket | disabled | TCP is the common case; UDS is opt-in for reverse-proxy setups. | | File descriptor passing | disabled | Only needed in inetd/systemd/launchd sandboxing scenarios. | diff --git a/src/v3/features/cors.md b/src/v3/features/cors.md index bf69e87..68b1090 100644 --- a/src/v3/features/cors.md +++ b/src/v3/features/cors.md @@ -23,6 +23,8 @@ static-web-server \ # --cors-allow-origins "*" ``` +Responses to requests with an allowed `Origin` header include `Origin` in the `Vary` header, so shared caches store a response per origin. SWS appends it to any `Vary` values already set, such as `Accept` on [automatic directory listings](./directory-listing.md#automatic-format), so caches still store each listing format separately. + ## Allowed headers The server also supports a list of [CORS allowed headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers) separated by commas. diff --git a/src/v3/features/ipv6-only.md b/src/v3/features/ipv6-only.md new file mode 100644 index 0000000..113d077 --- /dev/null +++ b/src/v3/features/ipv6-only.md @@ -0,0 +1,24 @@ +# IPv6-Only Host + +**SWS** binds the default `::` host as a dual-stack socket, so it accepts IPv6 and IPv4 connections and also takes the port for IPv4. + +The `--ipv6-only` option or its equivalent [SERVER_IPV6_ONLY](./../configuration/env.md#server-ipv6-only) env makes `::` accept IPv6 connections only and leaves the port free for IPv4, for example for another service listening on `0.0.0.0` at the same port. It is disabled by default. + +```sh +static-web-server -d ./public/ --ipv6-only +``` + +Or in the [configuration file](./../configuration/file.md): + +```toml +[general] +host = "::" +ipv6-only = true +``` + +## Behavior + +- The option applies to the main listener and the [HTTP to HTTPS redirect](./http-https-redirect.md) listener. +- SWS fails to start if the OS refuses to make the socket IPv6-only. +- A specific IPv6 host, such as `::1`, always accepts IPv6 connections only, so the option has no effect on it. +- SWS fails to start when the option is combined with an IPv4 host, such as `0.0.0.0`, with [file descriptor socket passing](./file-descriptor-socket-passing.md) (`--fd`) or with a [Unix domain socket](./unix-domain-socket.md) (`--unix-socket`). diff --git a/src/v3/index.md b/src/v3/index.md index 6df6b18..6f60969 100644 --- a/src/v3/index.md +++ b/src/v3/index.md @@ -56,6 +56,7 @@ SWS is designed to be **simple by default, powerful when needed**. You can point | [**Maximum Request Header Size**](./features/max-header-size) | Reject requests whose headers are larger than a configurable limit. | | [**Windows Service**](./features/windows-service) | Install SWS as a native Windows Service with `sc` or the installer. | | [**Docker**](./features/docker) | Official images on `scratch`, `Alpine`, and `Debian` for several architectures. | +| [**IPv6-Only Host**](./features/ipv6-only) | Keep the default `::` host IPv6-only and leave the port free for IPv4. | | [**Unix Domain Socket**](./features/unix-domain-socket) | Listen on a UDS path for secure, low-latency local proxying. | | [**File Descriptor Socket Passing**](./features/file-descriptor-socket-passing) | Pass a pre-opened socket via FD for seamless hot-reload setups. | | [**Worker Threads**](./features/worker-threads) | Tune the thread pool to balance latency and throughput. | diff --git a/src/v3/migration-guide.md b/src/v3/migration-guide.md index 314bd01..7ece9b5 100644 --- a/src/v3/migration-guide.md +++ b/src/v3/migration-guide.md @@ -173,7 +173,7 @@ With `--page-fallback`, requests for missing assets (e.g. `/favicon.ico` or a sc v3 binds the default `--host ::` as a dual-stack socket, so it accepts IPv4 too on Windows, FreeBSD and Linux with `net.ipv6.bindv6only=1`, where v2 listened on IPv6 only. It then also reserves the port for IPv4. -**Action:** If another service listens on `0.0.0.0` at the same port, SWS now fails with "address in use": change one of the ports, or bind SWS to a specific IPv6 address to stay IPv6-only. +**Action:** If another service listens on `0.0.0.0` at the same port, SWS now fails with "address in use": change one of the ports, or add `--ipv6-only` to keep `::` IPv6-only as in v2. See [IPv6-Only Host](./features/ipv6-only.md). ## Quick migration checklist @@ -192,4 +192,4 @@ v3 binds the default `--host ::` as a dual-stack socket, so it accepts IPv4 too 13. **Header size:** Raise `--max-header-size` if clients send headers over 16 KiB. 14. **Cache-Control:** No action needed. HTML now gets `no-cache`. 15. **Fallback page:** No action needed. Missing assets keep their `404`. -16. **Dual-stack:** Make sure no other service uses the same port on `0.0.0.0`. +16. **Dual-stack:** Make sure no other service uses the same port on `0.0.0.0`, or add `--ipv6-only`.