ADR-071. Topics (/, /feed.atom, /feed.rss, /feed.json, /likes, /tag/<name>) advertise the hub and themselves in Link headers and embedded links. Note changes bump a content version (fresh feeds in every process) and queue deliveries. /websub accepts subscriptions for these topics only; the worker verifies intent, delivers signed content with retries, and prunes expired leases, all through the SSRF-safe pinned fetcher. WEBSUB_HUB_URL switches to an external hub (publish pings). Also: the memory monitor no longer stops after the first request; RSS self link is /feed.rss. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
"""
|
|
WebSub hub endpoint (v2.10.0, ADR-071)
|
|
|
|
POST /websub with hub.mode subscribe/unsubscribe, hub.topic, hub.callback,
|
|
optional hub.secret and hub.lease_seconds. Answers 202 and verifies later
|
|
(spec 5.1); errors are 4xx with a plain-text reason.
|
|
"""
|
|
|
|
from flask import Blueprint, current_app, request
|
|
|
|
from starpunk.database import get_db
|
|
from starpunk.rate_limiter import RateLimiter
|
|
from starpunk import websub
|
|
|
|
bp = Blueprint("websub", __name__)
|
|
|
|
# Subscription requests per client IP per minute
|
|
_limiter = RateLimiter(limit=30, window_seconds=60)
|
|
|
|
|
|
def _text(message: str, status: int):
|
|
return message + "\n", status, {"Content-Type": "text/plain; charset=utf-8"}
|
|
|
|
|
|
@bp.route("/websub", methods=["POST"])
|
|
def hub():
|
|
if not websub.enabled():
|
|
return _text("WebSub is not enabled on this site", 404)
|
|
|
|
from starpunk.routes.webmention import get_client_ip
|
|
if not _limiter.is_allowed(get_client_ip()):
|
|
return _text("Too many requests", 429)
|
|
|
|
if "application/x-www-form-urlencoded" not in request.headers.get("Content-Type", ""):
|
|
return _text("Send an application/x-www-form-urlencoded body", 400)
|
|
|
|
try:
|
|
websub.accept_subscription_request(request.form, get_db(current_app))
|
|
except websub.SubscriptionError as e:
|
|
return _text(str(e), e.status)
|
|
|
|
return _text("Accepted; the subscription will be verified", 202)
|
|
|
|
|
|
@bp.route("/websub", methods=["GET"])
|
|
def hub_info():
|
|
return _text(
|
|
"WebSub hub for this site's own feeds. Subscribe with a POST "
|
|
"(https://www.w3.org/TR/websub/).", 200)
|