Expand description

§Static Web Server (SWS)

SWS is a cross-platform, high-performance and asynchronous web server for static files-serving.

Considerations:

This crate was published to make it possible for users to embed SWS with ease instead of working around it via forks. For example, allowing users to turn off default features like tls and so on.

However, because the library is highly coupled with the SWS binary project at this point, users might be limited by the exposed APIs, implementations, missing functionality, or dependencies.

In the future, we will eventually plan to make SWS library independent from the binary project.

That said, if fine-grained control and flexibility are needed then you could want to look at other alternatives like HTTP libraries or frameworks.

Pre-compile binaries:

This is the official SWS crate. If you are looking for platform pre-compile binaries then take a look at static-web-server.net/download-and-install.

§Overview

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

It is focused on lightness and easy-to-use principles while keeping high performance and safety powered by The Rust Programming Language.

Written on top of Hyper and Tokio runtime. It provides concurrent and asynchronous networking abilities as well as the latest HTTP/1 - HTTP/2 implementations.

It’s cross-platform and available for Linux, macOS, Windows and FreeBSD (x86/x86_64, ARM/ARM64) as well as Docker.

static-web-server

§Features

  • Built with Rust which is focused on safety, speed and concurrency.
  • Memory safe and very reduced CPU and RAM overhead.
  • Blazing fast static files-serving and asynchronous powered by latest Hyper, Tokio and a set of awesome crates.
  • Single 4MB (uncompressed) and fully static binary with no dependencies (Musl libc). Suitable for running on any Linux distro or Docker container.
  • Optional GZip, Deflate or Brotli compression for text-based web files only.
  • Compression on-demand via Accept-Encoding header.
  • Partial Content Delivery support for byte-serving of large files.
  • Optional Cache-Control headers for assets.
  • Termination signal handling with graceful shutdown ability and grace period.
  • HTTP/2 and TLS support.
  • Security headers for HTTP/2 by default.
  • HEAD responses.
  • Lightweight and configurable logging via tracing crate.
  • Customizable number of worker threads.
  • Optional directory listing.
  • CORS support.
  • Basic HTTP Authentication.
  • Customizable HTTP response headers for specific file requests via glob patterns.
  • Fallback pages for 404 errors, useful for Single-page applications.
  • Run the server as a Windows Service.
  • Configurable using CLI arguments, environment variables or a TOML file.
  • Default and custom error pages.
  • Custom URL rewrites and redirects via glob patterns.
  • Support for serving pre-compressed (Gzip/Brotli) files.
  • First-class Docker support. Scratch and latest Alpine Linux Docker images.
  • Ability to accept a socket listener as a file descriptor for use in sandboxing and on-demand applications (E.g systemd).
  • Cross-platform. Pre-compiled binaries for Linux, macOS, Windows and FreeBSD (x86,x86_64,ARM,ARM64).

§Cargo features

When building from the source, all features are enabled by default. However, you can disable just the ones you don’t need from the lists below.

FeatureDescription
Default
defaultActivates the default features.
allActivates all features including the default and experimental ones. E.g. this feature is used when building the SWS binaries.
experimentalActivates all unstable features.
HTTP2/TLS
http2Activates the HTTP2 and TLS feature.
Compression
compressionActivates auto-compression and compression static with all supported algorithms.
compression-brotliActivates auto-compression/compression static with only the brotli algorithm.
compression-deflateActivates auto-compression/compression static with only the deflate algorithm.
compression-gzipActivates auto-compression/compression static with only the gzip algorithm.
compression-zstdActivates auto-compression/compression static with only the zstd algorithm.
Directory Listing
directory-listingActivates the directory listing feature.
Basic Authorization
basic-authActivates the Basic HTTP Authorization Schema feature.
Fallback Page
fallback-pageActivates the Fallback Page feature.

Re-exports§

Modules§

  • basic_authbasic-auth
    Basic HTTP Authorization Schema module.
  • compressioncompression
    Auto-compression module to compress responses body.
  • Compression static module to serve compressed files directly from the file system.
  • It provides an arbitrary Cache-Control headers functionality for incoming requests based on a set of file types.
  • CORS module to handle incoming requests.
  • Module to append custom HTTP headers via TOML config file.
  • directory_listingdirectory-listing
    It provides directory listig and auto-index support.
  • Useful error type re-exports based on anyhow.
  • Error page module to compose an HTML page response.
  • fallback_pagefallback-page
    Fallback page module useful for a custom page default.
  • Request handler module intended to manage incoming HTTP requests.
  • Module to redirect HTTP requests to HTTPS.
  • Provides logging initialization for the web server.
  • Provides maintenance mode functionality.
  • Redirection module to handle config redirect URLs with pattern matching support.
  • Module that allows to rewrite request URLs with pattern matching support.
  • The module provides several HTTP security headers support.
  • Server module intended to construct a multi-threaded HTTP or HTTP/2 web server.
  • The module provides a custom Hyper service.
  • Module that provides all settings of SWS.
  • signalsUnix or Windows
    The module provides signals support like SIGTERM, SIGINT and SIGQUIT.
  • The static file module which powers the web server.
  • tlshttp2
    The module handles requests over TLS via Rustls.
  • Async transport module.
  • Module that allows to determine a virtual hostname.

Macros§