index : static-web-server.git

ascending towards madness

author Jose Quintana <joseluisquintana20@gmail.com> 2021-07-17 22:42:17.0 +00:00:00
committer Jose Quintana <joseluisquintana20@gmail.com> 2021-07-17 22:42:17.0 +00:00:00
commit
4dc8a25876b8188b75a911264b7787a24f86bd97 [patch]
tree
9ed4eae49751d61892bf85bf0c96e2e93817a9c2
parent
012b626ebf0b90259791e5d2a190d57c1e81b055
download
4dc8a25876b8188b75a911264b7787a24f86bd97.tar.gz

v2.0.0



Diff

 CHANGELOG.md | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 Cargo.lock   |  2 +-
 Cargo.toml   |  2 +-
 README.md    | 24 ++++++++++++++----------
 4 files changed, 78 insertions(+), 12 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2e0fa02..db085f5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,68 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

_**Note:** See changelog for v1 under the [1.x]https://github.com/joseluisq/static-web-server/blob/1.x/CHANGELOG.md branch._

## v2.0.0 - 2021-07-18

The second major stable release is finally available after around half a year of work. It introduces notable changes including new features, performance improvements and new targets support like ARM64 and OSes like FreeBSD.

This version was re-written almost from scratch on top of [Hyper]https://github.com/hyperium/hyper and [Tokio]https://github.com/tokio-rs/tokio runtime which give us the [Rust asynchronous ability]https://rust-lang.github.io/async-book/01_getting_started/02_why_async.html by default and latest HTTP/1 - HTTP/2 implementation improvements.
However it still try to keep the same principles of its first version: lightness and easy to use. Therefore a migration should not be a big deal.

Your feedback is very appreciated.

### Features

This list only shows new features not present in previous v1.

- Static Web Server is now asynchronous by default powered by latest Hyper and Tokio.
- It supports opt-in GZip, Deflate and Brotli compression for text-based web files only.
- HTTP/2 + TLS support (via `--http2` option).
- [Security headers]https://github.com/joseluisq/static-web-server/pull/44 like STS, CSP and others for HTTP/2 by default.
- Customizable number of worker threads (via `--threads-multiplier` option).
- [Redesigned directory listing]https://github.com/joseluisq/static-web-server/pull/41 (via `--directory-listing` option).
- Cache control header is now optional (via `--cache-control-headers`).
- Ability to accept a socket listener as a file descriptor for use in sandboxing and on-demand applications (E.g [systemd]http://0pointer.de/blog/projects/socket-activation.html). Via `--fd` option. Thanks to [@tim-seoss]https://github.com/tim-seoss.
- Binaries for various i686/x86_64 targets (Linux/Windows/FreeBSD) and ARM/ARM64 (Linux/Macos M1)

For the full list, options details and usage please check it out the [README]./README.md file.

### Breaking changes

This major version has few breaking changes.
However a migration should not represent a problem. Please have in mind the following changes:

- The server supports now only a root directory path (via `--root` or its equivalent env) so an assets path option is no longer required.
- Cache control headers is applied to assets in an arbitrary manner. See [src/control_headers.rs]src/control_headers.rs for more details.
- OpenSSL TLS for HTTP/1 is not longer supported instead for the HTTP/2 + TLS (via `--http2` option) the server uses [h2]https://github.com/hyperium/h2 which is on top of [Rustls]https://github.com/ctz/rustls. It means that instead of using a .p12 or .pfx file you can now use only a certificate file along with its private key. More details on [README]./README.md file.

The rest of known options are equivalent to v1 except the new ones of course.
However it's worth to always recommend to test this server update first with your applications on a development environment or similar.

Please see the full list of options with their details on the [README]./README.md file.

---

Changes after the latest `v2.0.0-beta.7` release:

__Performance__

- [157ade1]https://github.com/joseluisq/static-web-server/commit/157ade1 Decrease few allocations during 404/50x error page responses.
- [941572c]https://github.com/joseluisq/static-web-server/commit/941572c Reduce few allocations on control headers checking.

__Features__

- [012b626]https://github.com/joseluisq/static-web-server/commit/012b626 Cache control headers optional via `--cache-control-headers`.

__Refactorings__

- [5aa587f]https://github.com/joseluisq/static-web-server/commit/5aa587f Minor syntax improvements on static file module.
- [45988db]https://github.com/joseluisq/static-web-server/commit/45988db Minor style updates on server module.

__Docs__

- [5bcc629]https://github.com/joseluisq/static-web-server/commit/5bcc629 FreeBSD targets description.
- [dffdf5c]https://github.com/joseluisq/static-web-server/commit/dffdf5c Changelog support.

## v2.0.0-beta.7 - 2021-07-09

Seventh and last beta release `v2.0.0-beta.7` with notable changes.
diff --git a/Cargo.lock b/Cargo.lock
index 5c13a4a..253bcaf 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -846,7 +846,7 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"

[[package]]
name = "static-web-server"
version = "2.0.0-beta.7"
version = "2.0.0"
dependencies = [
 "anyhow",
 "async-compression",
diff --git a/Cargo.toml b/Cargo.toml
index 5603020..e4deda0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "static-web-server"
version = "2.0.0-beta.7"
version = "2.0.0"
authors = ["Jose Quintana <https://git.io/joseluisq>"]
license = "MIT OR Apache-2.0"
description = "A blazing fast and asynchronous web server for static files-serving."
diff --git a/README.md b/README.md
index 213e63c..689e208 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,11 @@
# Static Web Server [![CI]https://github.com/joseluisq/static-web-server/workflows/CI/badge.svg]https://github.com/joseluisq/static-web-server/actions?query=workflow%3ACI [![Docker Image Version (tag latest semver)]https://img.shields.io/docker/v/joseluisq/static-web-server/1]https://hub.docker.com/r/joseluisq/static-web-server/ [![Docker Image Size (tag)]https://img.shields.io/docker/image-size/joseluisq/static-web-server/1]https://hub.docker.com/r/joseluisq/static-web-server/tags [![Docker Image]https://img.shields.io/docker/pulls/joseluisq/static-web-server.svg]https://hub.docker.com/r/joseluisq/static-web-server/

**Status:** `v2` under **active** development. For the stable `v1` please refer to [1.x]https://github.com/joseluisq/static-web-server/tree/1.x branch.

> A blazing fast and asynchronous web server for static files-serving. ⚡

**Static Web Server** (or `SWServer` abbreviated) is a very small and fast production-ready web server suitable to serve static web files or assets.

_**Note:** For `v1` please refer to [1.x]https://github.com/joseluisq/static-web-server/tree/1.x branch._

## Features

- Built with [Rust]https://rust-lang.org which is focused on [safety, speed, and concurrency]https://kornel.ski/rust-c-speed.
@@ -15,7 +15,7 @@
- GZip, Deflate or Brotli compression for text-based web files only.
- Compression on demand via [Accept-Encoding]https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding header.
- [Partial Content Delivery]https://en.wikipedia.org/wiki/Byte_serving support for byte-serving of large files.
- [Cache Control]https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control headers for assets.
- Optional [Cache Control]https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control headers for assets.
- [HEAD]https://tools.ietf.org/html/rfc7231#section-4.3.2 responses.
- Lightweight and configurable logging via [tracing]https://github.com/tokio-rs/tracing crate.
- [Termination signal]https://www.gnu.org/software/libc/manual/html_node/Termination-Signals.html handling.
@@ -101,13 +101,14 @@ Server can be configured either via environment variables or their equivalent co
| `SERVER_COMPRESSION`  | Gzip, Deflate or Brotli compression on demand determined by the *Accept-Encoding* header and applied to text-based web file types only. See [ad-hoc mime-type list]https://github.com/joseluisq/static-web-server/blob/master/src/compression.rs#L20 | Default `true` (enabled) |
| `SERVER_DIRECTORY_LISTING`  | Enable directory listing for all requests ending with the slash character (‘/’) | Default `false` (disabled) |
| `SERVER_SECURITY_HEADERS` | Enable security headers by default when HTTP/2 feature is activated. Headers included: `Strict-Transport-Security: max-age=63072000; includeSubDomains; preload` (2 years max-age), `X-Frame-Options: DENY`, `X-XSS-Protection: 1; mode=block` and `Content-Security-Policy: frame-ancestors 'self'` | Default `false` (disabled) |
| `SERVER_CACHE_CONTROL_HEADERS` | Enable cache control headers for incoming requests based on a set of file types. The file type list can be found on [`src/control_headers.rs`]./src/control_headers.rs file. | Default `true` (enabled) |

### Command-line arguments

CLI arguments listed with `static-web-server -h`.

```
static-web-server 2.0.0-beta.7
static-web-server 2.0.0
Jose Quintana <https://git.io/joseluisq>
A blazing fast and asynchronous web server for static files-serving.

@@ -119,6 +120,9 @@ FLAGS:
    -V, --version    Prints version information

OPTIONS:
    -e, --cache-control-headers <cache-control-headers>
            Enable cache control headers for incoming requests based on a set of file types. The file type list can be
            found on `src/control_headers.rs` file [env: SERVER_CACHE_CONTROL_HEADERS=]  [default: true]
    -x, --compression <compression>
            Gzip, Deflate or Brotli compression on demand determined by the Accept-Encoding header and applied to text-
            based web file types only [env: SERVER_COMPRESSION=]  [default: true]
@@ -156,7 +160,7 @@ OPTIONS:
        --page50x <page50x>
            HTML file path for 50x errors. If path is not specified or simply don't exists then server will use a
            generic HTML error message [env: SERVER_ERROR_PAGE_50X=]  [default: ./public/50x.html]
    -p, --port <port>                                Host port [env: SERVER_PORT=]  [default: 80]
    -p, --port <port>                                      Host port [env: SERVER_PORT=]  [default: 80]
    -d, --root <root>
            Root directory path of static files [env: SERVER_ROOT=]  [default: ./public]

@@ -188,20 +192,20 @@ useful - especially for testing e.g. `systemfd --no-pid -s http::8091 -- path/to

```sh
# Scratch image (just the binary)
docker run --rm -it -p 8787:80 joseluisq/static-web-server:2.0.0-beta.7
docker run --rm -it -p 8787:80 joseluisq/static-web-server:2

# Or Alpine image
docker run --rm -it -p 8787:80 joseluisq/static-web-server:2.0.0-beta.7-alpine
docker run --rm -it -p 8787:80 joseluisq/static-web-server:2-alpine
```

### Dockerfile

```Dockerfile
# Scratch image (just the binary)
FROM joseluisq/static-web-server:2.0.0-beta.7
FROM joseluisq/static-web-server:2

# Or Alpine image
FROM joseluisq/static-web-server:2.0.0-beta.7-alpine
FROM joseluisq/static-web-server:2-alpine
```

### Docker stack
@@ -213,7 +217,7 @@ version: "3.3"

services:
  web:
    image: joseluisq/static-web-server:2.0.0-beta.7
    image: joseluisq/static-web-server:2
    environment:
      # Note: those envs are customizable but also optional
      - SERVER_HOST=127.0.0.1