How to change Iron's default 404 behaviour?

这一生的挚爱 提交于 2019-12-26 13:29:28

问题


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.
    }
}


来源:https://stackoverflow.com/questions/43284994/how-to-change-irons-default-404-behaviour

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!