Currently middleware uses this syntax:
async fn my_middleware<Ctx: 'static + Clone + Send + Sync>(
req: uhttp::Request,
res: uhttp::Response,
mut ctx: Ctx
) -> uhttp::Result<Option(uhttp::Request, uhttp::Response, Ctx)>
{
Ok(Some(req, res, ctx)) // Next middleware
}
Perhaps it's a good idea to use a "next" function so middleware can support custom error handling. Something like this (not exactly)
async fn my_middleware<Ctx: 'static + Clone + Send + Sync>(
req: uhttp::Request,
res: uhttp::Response,
mut ctx: Ctx, next: uhttp::router::MiddlewareFunc<Ctx>,
next: /* to be decided */
) -> uhttp::Result<()>
{
// Next middleware
match next(req, res, ctx) {
Ok(_) => Ok(()),
Err(err) => {
// Handle error if a handler errors out
res.write_head(StatusCode::INTERNAL_SERVER_ERROR).await?;
return Ok(())
}
}
}
Currently middleware uses this syntax:
Perhaps it's a good idea to use a "next" function so middleware can support custom error handling. Something like this (not exactly)