Skip to content

Commit 2fd8848

Browse files
authored
docs(v3): document v3.0.0-beta.4 changes (#27)
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.
1 parent 5713360 commit 2fd8848

9 files changed

Lines changed: 40 additions & 4 deletions

File tree

‎.vitepress/config.v3.mts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const v3: DefaultTheme.Config = {
5353
{ text: 'Idle Connection Timeout', link: '/v3/features/idle-timeout' },
5454
{ text: 'Maximum Connections', link: '/v3/features/max-connections' },
5555
{ text: 'Maximum Request Header Size', link: '/v3/features/max-header-size' },
56+
{ text: 'IPv6-Only Host', link: '/v3/features/ipv6-only' },
5657
{ text: 'File Descriptor Socket Passing', link: '/v3/features/file-descriptor-socket-passing' },
5758
{ text: 'Unix Domain Socket', link: '/v3/features/unix-domain-socket' },
5859
{ text: 'Worker Threads Customization', link: '/v3/features/worker-threads' },

‎src/v3/configuration/cli.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ Commands:
1919
2020
Options:
2121
-a, --host <HOST>
22-
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: ::]
22+
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: ::]
23+
--ipv6-only [<IPV6_ONLY>]
24+
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]
2325
-p, --port <PORT>
2426
Host port [env: SERVER_PORT=] [default: 8080]
2527
--open [<OPEN>]

‎src/v3/configuration/env.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ The server can be configured via the following environment variables.
99
1010
## SERVER_HOST
1111

12-
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 `::`.
12+
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 `::`.
13+
14+
## SERVER_IPV6_ONLY
15+
16+
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).
1317

1418
## SERVER_PORT
1519

‎src/v3/configuration/file.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Below is just an example showing all features with their default values.
2121

2222
#### Address & Root dir
2323
host = "::"
24+
ipv6-only = false
2425
port = 8080
2526
root = "."
2627

‎src/v3/defaults.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ When running `static-web-server` with no flags, you get:
2626
| Setting | Default | Rationale |
2727
| ----------------------- | --------------------------------- | -------------------------------------------------------------------------------- |
2828
| Host | `::` (all interfaces, dual-stack) | Reachable from any network interface, over IPv6 and IPv4 where the OS allows it. |
29+
| IPv6 only | disabled | `::` also accepts IPv4 by default; `--ipv6-only` leaves the IPv4 port free. |
2930
| Port | `8080` | Non-privileged port, no `root` needed. |
3031
| Unix socket | disabled | TCP is the common case; UDS is opt-in for reverse-proxy setups. |
3132
| File descriptor passing | disabled | Only needed in inetd/systemd/launchd sandboxing scenarios. |

‎src/v3/features/cors.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ static-web-server \
2323
# --cors-allow-origins "*"
2424
```
2525

26+
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.
27+
2628
## Allowed headers
2729

2830
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.

‎src/v3/features/ipv6-only.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# IPv6-Only Host
2+
3+
**SWS** binds the default `::` host as a dual-stack socket, so it accepts IPv6 and IPv4 connections and also takes the port for IPv4.
4+
5+
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.
6+
7+
```sh
8+
static-web-server -d ./public/ --ipv6-only
9+
```
10+
11+
Or in the [configuration file](./../configuration/file.md):
12+
13+
```toml
14+
[general]
15+
host = "::"
16+
ipv6-only = true
17+
```
18+
19+
## Behavior
20+
21+
- The option applies to the main listener and the [HTTP to HTTPS redirect](./http-https-redirect.md) listener.
22+
- SWS fails to start if the OS refuses to make the socket IPv6-only.
23+
- A specific IPv6 host, such as `::1`, always accepts IPv6 connections only, so the option has no effect on it.
24+
- 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`).

‎src/v3/index.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ SWS is designed to be **simple by default, powerful when needed**. You can point
5656
| [**Maximum Request Header Size**](./features/max-header-size) | Reject requests whose headers are larger than a configurable limit. |
5757
| [**Windows Service**](./features/windows-service) | Install SWS as a native Windows Service with `sc` or the installer. |
5858
| [**Docker**](./features/docker) | Official images on `scratch`, `Alpine`, and `Debian` for several architectures. |
59+
| [**IPv6-Only Host**](./features/ipv6-only) | Keep the default `::` host IPv6-only and leave the port free for IPv4. |
5960
| [**Unix Domain Socket**](./features/unix-domain-socket) | Listen on a UDS path for secure, low-latency local proxying. |
6061
| [**File Descriptor Socket Passing**](./features/file-descriptor-socket-passing) | Pass a pre-opened socket via FD for seamless hot-reload setups. |
6162
| [**Worker Threads**](./features/worker-threads) | Tune the thread pool to balance latency and throughput. |

‎src/v3/migration-guide.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ With `--page-fallback`, requests for missing assets (e.g. `/favicon.ico` or a sc
173173

174174
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.
175175

176-
**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.
176+
**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).
177177

178178
## Quick migration checklist
179179

@@ -192,4 +192,4 @@ v3 binds the default `--host ::` as a dual-stack socket, so it accepts IPv4 too
192192
13. **Header size:** Raise `--max-header-size` if clients send headers over 16 KiB.
193193
14. **Cache-Control:** No action needed. HTML now gets `no-cache`.
194194
15. **Fallback page:** No action needed. Missing assets keep their `404`.
195-
16. **Dual-stack:** Make sure no other service uses the same port on `0.0.0.0`.
195+
16. **Dual-stack:** Make sure no other service uses the same port on `0.0.0.0`, or add `--ipv6-only`.

0 commit comments

Comments
 (0)