Skip to content

Convert to an examples repo: curate to 4 teaching modules, strip distribution apparatus - #7

Merged
luthermonson merged 2 commits into
mainfrom
convert-to-examples
Aug 24, 2026
Merged

Convert to an examples repo: curate to 4 teaching modules, strip distribution apparatus#7
luthermonson merged 2 commits into
mainfrom
convert-to-examples

Conversation

@luthermonson

Copy link
Copy Markdown
Contributor

Convert middlewaremiddleware-examples

The official native-middleware modules are now compiled into the ePHPm binary (PR #410), so this repo is no longer a distribution registry. It becomes reference/teaching material: a small set of self-contained templates showing how to write your own custom ePHPm middleware.

Repo-level changes already applied (outside this PR): renamed middlewaremiddleware-examples (GitHub auto-redirects the old name), updated description + topics, and deleted the v0.1.0-rc.1 distribution pre-release.

Curated to four teaching examples

Chosen to cover the range, not every use case. Each module's implementation is now inlined into its own crate's lib.rs (impl + module docs + unit tests + the single declare! line), so a learner reads one file end to end. The shared ephpm-middleware-modules impl crate and the impl/shell split — which existed only to vendor every module into one binary, a distribution concern — are removed.

Example Teaches
api-key request-phase auth gate: header/query key, static-map or KV lookup with constant-time compare, forward consumer id to PHP, else 401
redirect simplest early-return: canonical scheme/host/trailing-slash 301/308; no deps, no KV
ratelimit using the KV store: fixed-window counter via atomic kv_incr_ttl, 429 + Retry-After, fail-open (keeps its fail-open integration test)
header-transform the response phase: declare!(Type, response), set request headers PHP sees + set/remove response headers out

Removed: jwt, cors, security-headers, maintenance-mode, ip-allowlist, request-id — they ship inside ePHPm now.

Stripped distribution apparatus

  • Deleted .github/workflows/release.yml (per-platform build/publish, SHA256SUMS + manifest.json generation).
  • Dropped the workspace deps only the removed modules used (hmac, sha2, base64ct, ipnetwork).
  • README: removed the ephpm middleware get / fetch / registry / manifest content (that CLI is gone).

Kept light so examples don't rot

  • ci.yml retained: fmt / clippy (-D warnings) / test / release-build on every PR + push to main. Comments simplified (no longer references the deleted release workflow).

Rewrote the README

Now a "how to write ePHPm native middleware" guide: what native middleware is, the versioned C ABI + the declare! macro, request vs response phase (references ePHPm #408), KV access via req.host(), building a cdylib, and mounting it by explicit path or bare name through the loader search path — with a clear note that the official modules are built into ePHPm and these are templates for custom modules.

Verification (local, Windows)

  • cargo +nightly fmt --all -- --check clean
  • cargo clippy --workspace --all-targets -- -D warnings clean
  • cargo test --workspace green (incl. the ratelimit fail_open integration test)
  • cargo build --workspace --release links all four cdylibs

Do not merge yet — opened for review.

…ribution apparatus

The official native-middleware modules are now compiled into the ePHPm binary,
so this repo becomes reference/teaching material for writing CUSTOM middleware
rather than a distribution registry.

- Curate to four self-contained examples covering the range:
  - api-key          request-phase auth gate (constant-time compare, KV lookup,
                     identity forwarding to PHP)
  - redirect         simplest early-return (canonical URL 301/308; no deps/KV)
  - ratelimit        KV-backed fixed-window limiter (kv_incr_ttl; fail-open),
                     keeps the fail-open integration test
  - header-transform response phase (declare!(Type, response))
  Each module's implementation is now inlined into its own crate's lib.rs
  (impl + tests + declare! in one readable file); the shared
  ephpm-middleware-modules impl crate and the impl/shell split (a
  vendor-into-one-binary distribution concern) are removed.

- Remove the other modules (jwt, cors, security-headers, maintenance-mode,
  ip-allowlist, request-id) — they ship inside ePHPm now.

- Strip the distribution apparatus: delete the per-platform build/publish
  release.yml (SHA256SUMS + manifest.json generation) and drop the workspace
  deps only those modules used (hmac, sha2, base64ct, ipnetwork).

- Keep a light ci.yml (fmt/clippy/test/release-build on PR + push) so the
  examples don't rot; simplify its comments.

- Rewrite the README as a "how to write ePHPm native middleware" guide: the
  versioned ABI, the declare! macro, request vs response phase (#408), KV
  access, building a cdylib, and mounting it by explicit path or bare name via
  the loader search path. Remove the removed `ephpm middleware get`/registry
  content, and note the official modules are built into ePHPm.

fmt/clippy(-D warnings)/test/release-build all clean; all four cdylibs link.
ePHPm already ships built-in rate limiting (`[server.limits]`: per-IP/per-site,
429 + Retry-After), so a ratelimit middleware example would wrongly imply users
should write their own instead of using the built-in. Curate to three examples:
api-key, redirect, header-transform.

- Remove the `ephpm-middleware-ratelimit` crate (impl, unit tests, and the
  fail-open integration test). `members = ["crates/*"]` drops the member
  automatically; no workspace dep was unique to it (subtle + ephpm-kv are still
  used by api-key).
- README: remove the ratelimit table row, layout line, and testing/verdict
  mentions; the KV-access section now points at api-key (kv_get) as the KV
  example — the KV-usage teaching is preserved there.

fmt/clippy(-D warnings)/test/release-build all clean; the three cdylibs link.
@luthermonson
luthermonson merged commit d0e5dfd into main Aug 24, 2026
4 checks passed
@luthermonson
luthermonson deleted the convert-to-examples branch August 24, 2026 03:07
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