Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,24 +340,27 @@ fn ensure_compiled_snapshot(state: &Arc<RwLock<AppState>>) -> Arc<CompiledRouter
///
/// Returns `Ok(None)` if [`run_rsgi`] (async) must be used. Middleware, CORS, and security-header
/// presets always defer to async.
pub fn try_rsgi_sync_short_circuit(
py: Python<'_>,
pub fn try_rsgi_sync_short_circuit<'py>(
py: Python<'py>,
state: &Arc<RwLock<AppState>>,
scope: &Bound<'_, PyAny>,
protocol: &Bound<'_, PyAny>,
scope: &Bound<'py, PyAny>,
protocol: &Bound<'py, PyAny>,
) -> PyResult<Option<PyObject>> {
let protocol_py: Py<PyAny> = protocol.as_any().clone().unbind();
let proto: String = scope.getattr("proto")?.extract()?;
let proto_obj = scope.getattr("proto")?;
let proto = proto_obj.extract::<&str>()?;
if proto == "websocket" {
return Ok(None);
}
if proto != "http" {
return Ok(Some(py.None()));
}
let method: String = scope.getattr("method")?.extract()?;
let path: String = scope.getattr("path")?.extract()?;
let method_obj = scope.getattr("method")?;
let method = method_obj.extract::<&str>()?;
let path_obj = scope.getattr("path")?;
let path = path_obj.extract::<&str>()?;
let is_head = method == "HEAD";
let snapshot = state.read().hot_snapshot();
let protocol_py: Py<PyAny> = protocol.clone().unbind();

// Native CORS preflight handling (issue #218)
if method == "OPTIONS" {
Expand Down Expand Up @@ -433,7 +436,7 @@ pub fn try_rsgi_sync_short_circuit(
Some(c) => c,
None => ensure_compiled_snapshot(state),
};
let route_out = match match_route_compiled(&compiled, &method, &path) {
let route_out = match match_route_compiled(&compiled, method, path) {
None => {
return Err(pyo3::exceptions::PyValueError::new_err("method"));
}
Expand All @@ -455,8 +458,8 @@ pub fn try_rsgi_sync_short_circuit(
run_trivial_sync_route(
py,
&protocol_py,
&method,
&path,
method,
path,
is_head,
entry,
scope,
Expand All @@ -468,7 +471,7 @@ pub fn try_rsgi_sync_short_circuit(
Ok(None)
}
None => {
let m = methods_matching_path_compiled(&compiled, &path);
let m = methods_matching_path_compiled(&compiled, path);
if m.is_empty() {
response::send_text_sync(
py,
Expand Down
Loading