Skip to content

Commit

Permalink
fix: before request middleware for file uploads (#785)
Browse files Browse the repository at this point in the history
* fix: before request middleware for file uploads

* update

* fix body handling
  • Loading branch information
sansyrox authored Apr 12, 2024
1 parent ada44b1 commit cd5fa74
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/executors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ where
let kwargs = function.kwargs.as_ref(py);

let function_args = function_args.to_object(py);
debug!("Function args: {:?}", function_args);

match function.number_of_params {
0 => handler.call0(),
Expand Down Expand Up @@ -84,6 +85,7 @@ where
} else {
Python::with_gil(|py| -> Result<MiddlewareReturn> {
let output = get_function_output(function, py, input)?;
debug!("Middleware output: {:?}", output);
match output.extract::<Response>() {
Ok(o) => Ok(MiddlewareReturn::Response(o)),
Err(_) => Ok(MiddlewareReturn::Request(output.extract::<Request>()?)),
Expand Down
11 changes: 5 additions & 6 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use log::debug;
use pyo3::{
exceptions::PyValueError,
prelude::*,
Expand Down Expand Up @@ -78,9 +79,8 @@ pub fn get_body_from_pyobject(body: &PyAny) -> PyResult<Vec<u8>> {
} else if let Ok(b) = body.downcast::<PyBytes>() {
Ok(b.as_bytes().to_vec())
} else {
Err(PyValueError::new_err(
"Could not convert specified body to bytes",
))
debug!("Could not convert specified body to bytes");
Ok(vec![])
}
}

Expand All @@ -90,9 +90,8 @@ pub fn get_description_from_pyobject(description: &PyAny) -> PyResult<Vec<u8>> {
} else if let Ok(b) = description.downcast::<PyBytes>() {
Ok(b.as_bytes().to_vec())
} else {
Err(PyValueError::new_err(
"Could not convert specified description to bytes",
))
debug!("Could not convert specified response description to bytes");
Ok(vec![])
}
}

Expand Down

0 comments on commit cd5fa74

Please sign in to comment.