Skip to content

feat: upgrade to Mercure 1.0 alpha 3 - #2611

Draft
dunglas wants to merge 1 commit into
mainfrom
mercure-1.0-alpha3
Draft

feat: upgrade to Mercure 1.0 alpha 3#2611
dunglas wants to merge 1 commit into
mainfrom
mercure-1.0-alpha3

Conversation

@dunglas

@dunglas dunglas commented Aug 17, 2026

Copy link
Copy Markdown
Member

Upgrades github.com/dunglas/mercure and github.com/dunglas/mercure/caddy from v0.24.2 to v1.0.0-alpha.3, and adapts the integration to the protocol changes of draft-dunglas-mercure-08.

mercure_publish()

The hub validates updates before dispatching them, so the function now distinguishes the caller's mistakes from a failed publication:

  • a ValueError carrying the reason for a topic addressing the reserved /.well-known/mercure namespace or equal to *, an $id starting with # or equal to earliest, a $type equal to mercure, control characters, invalid UTF-8 $data, or no topic at all;
  • a RuntimeException with the message of the hub when the dispatch fails.

The negative values of $retry are also rejected, as the protocol only allows digits in that field.

An enum in frankenphp.h replaces the status codes go_mercure_publish() returned as bare integers. On the way, an array of topics that cannot be converted no longer reports No Mercure hub configured.

Hot reloading

The subscribe query parameter of the protocol is match, so $_SERVER['FRANKENPHP_HOT_RELOAD'] advertises /.well-known/mercure?match=<topic>. The topic parameter it replaces is only honored by a hub built with the deprecated_topic tag, which FrankenPHP doesn't set.

Hub configuration

Setting publisher_jwt or subscriber_jwt without protocol_version_compatibility is a configuration error now, because that mode also drops the required exp, the audience check, the at+jwt check and the issuer check. The keys are bound to a trusted issuer instead:

mercure {
	issuer {$MERCURE_TRUSTED_ISSUERS:https://localhost} {
		publisher {
			jwt {env.MERCURE_PUBLISHER_JWT_KEY} {env.MERCURE_PUBLISHER_JWT_ALG}
		}
		subscriber {
			jwt {env.MERCURE_SUBSCRIBER_JWT_KEY} {env.MERCURE_SUBSCRIBER_JWT_ALG}
		}
	}
}

php-server --mercure and the sample Caddyfile follow, and the access tokens using the 0.x mercure claim are rejected: FrankenPHP is built without the compatibility tags of the hub.

Notes

  • The translations of docs/mercure.md still describe the 0.x configuration.
  • The Symfony Mercure example needs symfony/mercure 0.8 for ProtocolVersion::V1, unreleased as this hub is still an alpha.

Publish-side validation is part of the protocol now: report what
Update.Validate() rejects (reserved topics and event types, forbidden
event IDs, invalid UTF-8 data) as a ValueError carrying the reason, and
the dispatch failures as a RuntimeException.

The subscribe query parameter becomes "match", so hot reloading advertises
its topic with it. The publisher_jwt and subscriber_jwt directives now
require the compatibility mode, which drops the audience, expiration and
issuer checks: bind the keys to a trusted issuer instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant