-2

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.

Yves Dorfsman
  • 2,684
  • 3
  • 20
  • 28

1 Answers1

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.
    }
}
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
L. L. Blumire
  • 345
  • 1
  • 2
  • 9
  • Adding this to `iron::middleware::AfterMiddleware` is sufficient to make it the default? – Yves Dorfsman Apr 07 '17 at 19:17
  • @YvesDorfsman Adding that as an aftermiddleware to the chain your website is mounted on would be, as all responses would go through it before being sent out. You're looking for iron::middleware::Chain::link_after I believe – L. L. Blumire Apr 08 '17 at 09:47