Skip to content

fix(handler): route passthrough, bypass and the response pass through the engine like fastapi-guard - #39

Merged
rennf93 merged 1 commit into
masterfrom
fix/engine-parity
Oct 15, 2026
Merged

rennf93 merged 1 commit into
masterfrom
fix/engine-parity

Conversation

@rennf93

@rennf93 rennf93 commented Oct 15, 2026

Copy link
Copy Markdown
Member

Summary

Aligns the Tornado adapter with fastapi-guard's engine routing.

  • Passthrough and the route all-checks bypass go through the engine BypassHandler: a request with no client address gets the fail_secure 403, excluded paths stay scoped (checks still run), and a bypassed route calls the real handler method with the modifier applied.
  • SecurityHandler.finish() runs the engine response pass before the response is flushed, instead of on_finish after it was sent. custom_response_modifier, the security headers, CORS and return-rule effects now reach the client, body-based return rules see the buffered body, and global behavior return rules are passed.
  • Blocked, preflight and bypass responses skip the response pass, so they emit no request metrics. Excluded paths still reach it.
  • Security headers and CORS are no longer reimplemented before the handler. Blocked responses carry CORS only, like fastapi-guard.
  • A Redis failure during initialization returns the 503 with Retry-After.
  • SecurityMiddleware.apply_pre_flight_headers is removed (it was the reimplemented path), and the docs describe the new flow.
  • The guard-core floor moves from >=4.0.0 to >=4.1.0, the first release with the engine APIs used and the floor the other adapters declare.

Streamed responses that call flush() before finish() have their headers on the wire already, so the pass observes them (metrics, return rules over the buffered body) but cannot change them.

Tests

New tests/test_engine_parity.py runs a real Tornado server and client against the real engine handlers. The tests that asserted the old _check_bypass behavior and the removed pre-flight headers are replaced. Full suite with --cov-fail-under=100 and pre-commit run --all-files pass.

Closes #38

… the engine like fastapi-guard

Use the engine BypassHandler for passthrough and the route all-checks bypass, with the real handler method as the downstream. Run the engine response pass from SecurityHandler.finish before the response is flushed, so the modifier, security headers, CORS and body-based and global return rules take effect. Emit request metrics only for responses that reach the view. Return a 503 when Redis is unavailable at initialization. Align the guard-core floor with the other adapters.
@github-actions github-actions Bot added documentation Docs, README, CHANGELOG, governance files area: adapters Touches tornadoapi_guard/adapters.py (request/response protocol implementations) tests Test suite changes dependencies pyproject.toml or uv.lock labels Oct 15, 2026
@rennf93
rennf93 merged commit f59709b into master Oct 15, 2026
13 checks passed
@rennf93
rennf93 deleted the fix/engine-parity branch October 15, 2026 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: adapters Touches tornadoapi_guard/adapters.py (request/response protocol implementations) dependencies pyproject.toml or uv.lock documentation Docs, README, CHANGELOG, governance files tests Test suite changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tornado adapter diverges from the engine request/response flow used by fastapi-guard

1 participant