Middleware
interface Middleware
A HTTP server middleware, which can be used to transform a handler.
Example
nv
use std.net.http.server.{Handler, Middleware, func_handler, Response};
struct MyMiddleware {
value: string,
}
impl MyMiddleware {
pub fn new(value: string): MyMiddleware {
return MyMiddleware { value };
}
pub fn transform(self, handler: Handler): Handler {
return handler.after(|resp| {
resp.set_header("X-My-Header", self.value);
return resp;
});
}
}
let my_middleware = MyMiddleware.new("my-value");
let handler = func_handler(|req| Response.text("Hello, world!"))
.with(my_middleware);
Methods