Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
403 views
in Technique[技术] by (71.8m points)

rust - How to change Iron's default 404 behaviour?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...