Open danechitoaie opened 9 months ago
First thought: Define a global mutexed variable, and use this here. Then the changed value will be used here. See https://doc.rust-lang.org/std/sync/struct.OnceLock.html Init it before starting the server and use set in other functions or another request handler to change the value at runtime. Not entirely sure about the performance implications, but normally mutexes and the likes are unproblematic up to at least 100k requests per second.
For now what I did was to copy over SizeLimit middleware into my src folder and then modify it to read the config from req.data
;
async fn call(&self, req: Request) -> Result<Self::Output> {
let app_config = req.data::<AppConfig>();
let size_limit = match app_config {
Some(app_config) => app_config.size_limit,
None => 0,
};
...
I don't like that I had to copy it, but it had just few lines of code so I guess it's not that big of a problem. Still not sure if this is the best way, or there's a better one.
Looking at
examples/openapi/poem-middleware/src/main.rs
I see that we can apply a "transform" function that applies a middleware to the desired API endpoint.My function is like this:
How can we make the size param dynamic? So that I don't hardcode it to 1024?