Skip to main content

A FastAPI middleware to handle the GNU Headers (Memorial Headers) of the Clacks (Going Postal Terry Pratchett) for 'sending people home'.

Project description

Clacks GNU middleware

Lightweight FastAPI/Starlette middleware that keeps the tradition alive by adding the X-Clacks-Overhead HTTP header. Incoming headers are preserved, defaults can be configured, and duplicates are removed case-insensitively.

What it does

  • Adds X-Clacks-Overhead to every response, prefixed with GNU and joined by commas.
  • Merges incoming request names, your configured defaults, and any names already set on the response.
  • Deduplicates names case-insensitively to avoid repeated entries.
  • Simple configuration via a shared clacks_config object.

Install

pip install clacks-gnu-middleware

For local development:

pip install -e .
pip install -r requirements.txt  # tooling & test extras

Quick start (FastAPI)

from fastapi import FastAPI
from clacks_gnu_middleware.clacks_middleware import clacks_middleware, clacks_config

app = FastAPI()

# Optional: customize defaults before registering the middleware
clacks_config.default_names.extend([
    "Ada Lovelace",
    "Alan Turing",
])

app.middleware("http")(clacks_middleware)

@app.get("/ping")
async def ping():
    return {"status": "ok"}

# Run with: uvicorn app.application:app --reload

Header behavior

  • Header name: X-Clacks-Overhead.
  • Values are emitted as GNU <name>, joined with commas.
  • Order: configured defaults → incoming header values → names already set on the response.
  • Names are deduplicated (case-insensitive). Empty or non-GNU values are ignored.

Testing

pytest

Notes

  • The middleware uses a module-level clacks_config; set defaults before registering the middleware to avoid runtime mutation.
  • License: GPL-3.0 (see LICENSE).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clacks_gnu_middleware-0.0.2.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clacks_gnu_middleware-0.0.2-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file clacks_gnu_middleware-0.0.2.tar.gz.

File metadata

  • Download URL: clacks_gnu_middleware-0.0.2.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for clacks_gnu_middleware-0.0.2.tar.gz
Algorithm Hash digest
SHA256 8371df408e92687af76c744c4459fff5ad4cab3c367af43259abf4449df27955
MD5 38145c53c0ebc7d726b245dc94c13735
BLAKE2b-256 2d6071d217a5c5b52146cb18f10b41a92a156a5b378c71f5fccd6c3f6a8b1554

See more details on using hashes here.

File details

Details for the file clacks_gnu_middleware-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for clacks_gnu_middleware-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e33b003c7e52d466d3a0c29a108646ce91fb7457ccf8bc03c5efa7f4d03689ea
MD5 13ed690af8a440d79df3c31b87e56356
BLAKE2b-256 84ac2afc8581ddfe9765cfd8701d04b04308584a60d71392910d49b37ffc6a81

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page