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.1.tar.gz (16.6 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.1-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: clacks_gnu_middleware-0.0.1.tar.gz
  • Upload date:
  • Size: 16.6 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.1.tar.gz
Algorithm Hash digest
SHA256 7cd180454760cf99a39298ca2280de1a67ec7d41fb735cf56573787b77cb4a8b
MD5 5b6330797f4347f12faa9a2b786e0fd4
BLAKE2b-256 54a23072d64edd4539d85dc2e81b19ba11bb7ec45b98e5756ef799ad0d396af0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for clacks_gnu_middleware-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8649a5930fafa4e2e67c7afb9dd8bc6c239b70f989b5a6481a42d126a2d9f7e2
MD5 731ecf8cb40e23d093aebb5fd8572a56
BLAKE2b-256 89f88fe46b270d90aaeaa4af788fa22208980df8d8b9d29423ed06f20dfd1904

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