Skip to main content

blackbull-htcpcp

A BlackBull extension implementing HTCPCP — the Hyper Text Coffee Pot Control Protocol from RFC 2324 (1998 April Fool's) and its tea-pot extension RFC 7168 (2014 April Fool's).

PyPI Python License

The joke is well-known. The reason to actually ship it is that HTCPCP is a small, frozen RFC that uses every awkward corner of HTTP at once — a custom method, a custom status code, a custom content type, an application-defined request header with its own grammar, and error semantics that aren't really about HTTP itself. Implementing it end-to-end in roughly 350 lines on top of an unmodified web framework makes a fine worked example for how far HTTP can be pushed as an application-protocol carrier.

Here is what the package actually puts on the wire:

BREW /pot HTTP/1.1                ← the real RFC 2324 verb (POST still works as an alias)
Host: localhost:8000
Accept-Additions: cream; sugar

HTTP/1.1 200 OK
Content-Type: message/coffeepot

{"pot-type": "coffee", "state": "ready", "additions": ["cream", "sugar"]}

Ask a teapot to brew coffee, and it answers honestly:

POST /pot HTTP/1.1
Host: localhost:8000

HTTP/1.1 418 I'm a teapot
Content-Type: message/coffeepot

{"error": "I'm a teapot", "pot-type": "teapot"}

All of it sits on BlackBull's documented init_app(app) extension surface — no framework fork, no monkey-patches. See src/blackbull_htcpcp/extension.py.

Install

pip install blackbull-htcpcp

Use

from blackbull import BlackBull
from blackbull_htcpcp import HtcpcpExtension

app = BlackBull()
HtcpcpExtension(app=app, pot_type='coffee')   # or pot_type='teapot'

# Deferred form, if you configure the app elsewhere:
ext = HtcpcpExtension(pot_type='teapot')
ext.init_app(app)

# Multiple pots on one app — pick a path per instance (default '/pot'):
HtcpcpExtension(app=app, pot_type='teapot', path='/teapot')  # RFC 7168 teapot

After init_app(app) the live extension sits at app.extensions[f'htcpcp:{path}'] ('htcpcp:/pot' by default). Four routes (BREW / PROPFIND / WHEN / GET) are registered on the mount path, a readiness route at f'{path}/when', plus an app.on_error(418) handler so any 418 the rest of the app emits gets the same message/coffeepot body.

The RFC 2324 verbs are exposed as a public StrEnum, and 418 is re-exported for discoverability:

from http import HTTPMethod

from blackbull_htcpcp import HtcpcpMethod, IM_A_TEAPOT

# StrEnum: members compare equal to plain strings and mix freely
# with http.HTTPMethod in route registrations.
@app.route(path='/my-pot', methods=[HtcpcpMethod.BREW, HTTPMethod.POST])
async def my_brew(scope, receive, send): ...

assert HtcpcpMethod.BREW == 'BREW'
assert IM_A_TEAPOT == 418          # http.HTTPStatus.IM_A_TEAPOT

What it implements

  • BREW — start brewing. Registered as a first-class BREW route on /pot (BlackBull ≥ 0.42.1 dispatches arbitrary method tokens); POST is kept as a backwards-compatible alias.
  • PROPFIND — inspect the pot's metadata. Exposed via GET in the same window; native PROPFIND verb gated on the same framework change.
  • WHEN — readiness check (GET /pot/when).
  • 418 I'm a teapot — RFC 2324 §2.2.2. A teapot brewing anything that isn't tea returns 418. Coffee pots return 200 for any brew request.
  • message/coffeepot — content type on every /pot response, success or error.
  • Accept-Additionscream; sugar; vanilla etc. Parsed, lower-cased, validated.

Configuration

Parameter Default Notes
pot_type 'coffee' 'coffee' or 'teapot'. Decides which Accept-Additions are valid and when 418 fires.
capacity_ml 1500 Reported via PROPFIND. Doesn't enforce anything — the pot is metaphorical.
path '/pot' Mount path for the pot resource (readiness at f'{path}/when'). Any absolute path; give each instance its own path to host several pots on one app.

Security

HTCPCP is a joke; the parser isn't. Accept-Additions is rejected when an addition token contains:

  • CRLF or bare LF (response splitting),
  • a NULL byte,
  • non-printable control characters (other than horizontal tab — valid OWS per RFC 9110 §5.6.3),
  • more than 256 characters,

or when the request carries more than 64 addition tokens. BREW request bodies are capped at 1 MiB. See tests/test_htcpcp.py for the full S001–S015 matrix.

How it fits

blackbull-htcpcp is the second external extension built on BlackBull's init_app(app) convention, after blackbull-session. It exists partly to prove that the extension surface can carry a non-trivial application protocol — custom methods, custom content types, custom error semantics — without modifications to the framework itself. The cultural reference is IPoAC (RFC 1149, implemented by Bergen Linux User Group in 2001): the joke RFCs are funny because they could actually be implemented, and implementing them teaches something about the layer underneath.

License

Apache License 2.0 — © TOKUJI.

Download files

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

Source Distribution

blackbull_htcpcp-0.3.0.tar.gz (22.9 kB view details)

Uploaded Source

Built Distribution

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

blackbull_htcpcp-0.3.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file blackbull_htcpcp-0.3.0.tar.gz.

File metadata

  • Download URL: blackbull_htcpcp-0.3.0.tar.gz
  • Upload date:
  • Size: 22.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for blackbull_htcpcp-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b5bfca7df308ffb917f5e01b677a846617b8051260820abba5fbe5a9c2bfd8f3
MD5 8ac5fa2b5e21c790cb071337297f7630
BLAKE2b-256 021bc1fc9aafba9c0e750d8853159b16c5d75f1344119821a32430820b31e811

See more details on using hashes here.

Provenance

The following attestation bundles were made for blackbull_htcpcp-0.3.0.tar.gz:

Publisher: publish.yml on TOKUJI/blackbull-htcpcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file blackbull_htcpcp-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for blackbull_htcpcp-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ccf7629d645aa5fccdb310f80824cd8b55e59223e245946e356cf25382f26c37
MD5 787fb0c5121623e6d5baebaee7d5b8e3
BLAKE2b-256 a762ca278cd898fe5357858d3d43c7c29c717b10f29c5f19b8187fd11a5fadfe

See more details on using hashes here.

Provenance

The following attestation bundles were made for blackbull_htcpcp-0.3.0-py3-none-any.whl:

Publisher: publish.yml on TOKUJI/blackbull-htcpcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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