I want to change the default 404 behaviour in a small Iron application. I want to add some simple text content to it, nothing complicated like using templates.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Iron has an example for how to do this.
Create and start your program on an iron::Chain
, and then create an iron::middleware::AfterMiddleware
. This middleware could look like:
fn custom_404(req: &mut Request, res: &mut Response) -> IronResult<Response> {
if response.status == Some(Status::NotFound) {
// Create a response as desired here.
}
}