-
Notifications
You must be signed in to change notification settings - Fork 75
Open
Labels
Description
Hi guys. I saw that already there are two issue with such behavior. However, they have not solution. I had some problem with crate mount and crate route.
Simple example
extern crate iron;
extern crate router;
extern crate mount;
use iron::{Iron, Request, Response, IronResult};
use iron::status;
use router::{Router};
fn main() {
let mut router = Router::new();
router.get("/get", query_handler, "query_handler");
fn handler(_: &mut Request) -> IronResult<Response> {
Ok(Response::with((status::Ok, "OK")))
}
fn query_handler(_: &mut Request) -> IronResult<Response> {
Ok(Response::with((status::Ok, "query")))
}
let mut mount = mount::Mount::new();
mount
.mount("/", handler)
.mount("/api", router)
;
Iron::new(mount).http("127.0.0.1:3000").unwrap();
}
When i create request like GET http://www.example.com/api/get/ i had redirect to http://www.example.com/get . This because the mount crate cuts url in there https://github.com/iron/mount/blob/master/src/mount.rs#L119
To use both the crates I had fork this project and add dependency route to mount and add this
let original = req.extensions.get::<mount::OriginalUrl>();
if original.is_some() {
url = original.unwrap().clone();
}
To https://github.com/iron/router/blob/master/src/router.rs#L178
Now all work fine. But the decision I do not like.
The only reasonable solution to move in iron crate this struct
pub struct OriginalUrl;
impl typemap::Key for OriginalUrl { type Value = Url; }
And use in mount and route crate