HTTP/1.1 · HTTP/2 · HTTP/3 for macOS and Linux

A fast, modular web server for macOS and Linux.

PhotonHTTP is written in Swift 6 with Swift Concurrency and no package dependencies. Serve a folder with one command, run a full site from one JSON file, or compose its components into your own Swift server.

  • macOS 15 or later, and Linux
  • Swift 6, strict concurrency
  • Zero package dependencies

Quick start

Install the photon command, then serve any folder as a static website.

1Install

Clones the repository, builds a release binary with your Swift toolchain and installs photon to /usr/local/bin, asking for your password only if that folder needs sudo.

$ curl -fsSL https://photon-http.sstools.co/install.sh | bash

On macOS 15+, with a Swift 6.4 toolchain (Xcode or swift.org). For Linux, see Running on Linux. Options: --prefix DIR, --version REF. More

2Serve a folder

Serves the current directory on http://127.0.0.1:8080/; every directory serves its index.html. Ctrl-C stops it.

$ cd ~/Sites/example
$ photon serve
listening 127.0.0.1:8080

Pick a folder and port with photon serve public --port 8000; share on your network with --host 0.0.0.0.

What you get

A small core plus optional components. A component that is not configured is not in the request path at all.

HTTP/1.1, HTTP/2, HTTP/3

Keep-alive, pipelining, chunked bodies and 100-continue; HTTP/2 over TLS via ALPN (optional h2c), passing h2spec 146/146; HTTP/3 over QUIC with Alt-Svc discovery. Protocols

Static files

Index files, MIME types, strong ETags, conditional requests (304/412), single Range (206), sendfile for large files, an in-memory cache for small ones, traversal and dotfile protection. Static sites

Compression

Brotli, gzip and deflate. Static files are compressed once, or served from .br/.gz sidecars. Compression

Virtual hosts and error pages

Several sites on one listener, with wildcard names; custom per-site or generated error pages. Virtual hosts

TLS without the keychain

Identities load from a PKCS#12 file in memory only: nothing is installed and nothing prompts. Certificates reload on SIGHUP without dropping connections. TLS

Authentication

HTTP Basic (PBKDF2), HS256 JWT and bearer tokens per path prefix, with failure limiting. Auth

Reverse proxy

Forward paths to local apps over TCP or Unix sockets, with pooling, timeouts, retries, health checks and WebSocket tunnelling. Dynamic sites

WebSockets

Over HTTP/1.1, HTTP/2 and HTTP/3, with permessage-deflate. Write endpoints in Swift with WebSocketUpgrade, or proxy them to a backend. WebSockets

Access log and metrics

Common, Combined or JSON access logs and a Prometheus /metrics endpoint; connection limits and timeouts. Logs

Graceful reload and restart

SIGHUP or a file change reloads the config without dropping requests; photon restart applies any change in process, with no gap in service; SIGINT/SIGTERM drain open connections. Reload

Components for your own server

Every part is a Swift library product. Add a Router and your own handlers, keep only what you need. Choosing components

Built for macOS, runs on Linux

On macOS: BSD sockets, kqueue and sendfile for cleartext; Network.framework for TLS and QUIC. On Linux: epoll, OpenSSL for TLS and ngtcp2 for QUIC, with the same config file. Binds 127.0.0.1 unless you ask otherwise. Running on a Mac · Running on Linux

Fast where it counts

With kept-alive connections PhotonHTTP serves static files faster than nginx, h2o, Apache and Caddy on the same machine, behind only lighttpd.

~97k req/s

Static files over keep-alive HTTP/1.1 at 64 connections; 14–20% ahead of nginx.

21.9k conn/s

New connections accepted on the BSD socket listener, vs nginx's 18.0k.

146/146

h2spec conformance for HTTP/2, with limits against the known HTTP/2 attacks.

~8 MiB

Server memory while sending a 1 GiB file with sendfile(2).

Measured on an Apple M4 Pro over loopback with the load client on the same machine; treat the numbers as relative. Performance notes and records

Two ways to use it

Run the ready-made server, or build your own from its parts.

The photon server, one JSON file

A static site with an app behind it, compressed and logged:

{
  "root": "public",
  "compression": true,
  "accessLog": { "path": "logs/access.log", "format": "combined" },
  "proxy": [ { "path": "/api", "upstream": "http://127.0.0.1:9000" } ]
}

Run it with photon --config http-config.json. Every key: the config reference.

Your own server in Swift

Compose only the components you need; the chain is built at compile time.

let server = Server(listeners: [try BSDSocketListener()], protocols: [HTTP1()]) {
    AccessLog(format: .combined, destination: .standardOutput)
    Compression()
    router              // a Router with your routes
    files               // StaticFiles, the terminal handler
}
try await server.run()

See Choosing components and Examples/custom-server.