Skip to content

perf: CORS/security-headers merge goes through Python on every request with Origin, disables sync short-circuit entirely #218

Description

@ZhuchkaTriplesix

Where: src/dispatch.rs:350, 598, 1295, 1592.

Registering CORS via apply_cors installs a request middleware, which unconditionally disables try_rsgi_sync_short_circuit for every request on the app (dispatch.rs:350 bails to the full async path whenever request_middleware is non-empty), even for routes that don't need it. On top of that, every response header merge for CORS/security-headers calls back into Python (response_header_pairs) and copies the body through into_vec.

Fix direction: compile CORSConfig/SecurityHeadersConfig into native Rust structs at set_cors/set_security_headers time so header merging and CORS preflight can happen without a Python call, and stop routing all requests through the async path just because middleware exists — only requests actually needing middleware should skip the fast path.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions