I have a simple rest sort of skin around a large text file that I need to query interactively. It can involve a heavy compute so I used rust. I have put a simple restful skin with Iron. Note that I haven't done much with rust. This is just running on localhost.
pub fn query<'a>(parsed: &'a Parsed, context:&Context) -> {
// parsed.keys is a hash containing config informtion
// context is what I query
let local_port = format!("{}:{}", "localhost", parsed.keys[AS_SERVER]);
fn test_connect<'a>(r: &'a mut Request, c:&'a Context) -> IronResult<Response> {
let url = r.url.to_string();
let result = // some logic
Ok(Response::with((status::Ok, format!("requested=\"{}:{}\"\n", url, result))))
}
let mut router = Router::new();
router.get("*", move |r: &mut Request| test_connect(r, &context));
let connection_status = Iron::new(router).http(&local_port[..]);
connection_status.ok().expect("could not connect");
}
Now my question is how do I get control to return out of the listening loop in
Iron::new(router).http(&local_port[..]);
I just want to say curl http://localhost/done
and have the listen function exit and so some logging and and move on. Is this possible to do this? I have tried panic-ing, but even that won't exit the listening loop?
I tried returning something like Err(IronError::new(StringError(url),status::ServiceUnavailable))
That status::ServiceUnavailable
is just something random - it needed something: I know it's not semantically correct, not sure what to use. But the error doesn't have any handler on it, so it goes away silently.
I suppose I will set something up with aftermiddleware, but I don't know what?