Repository: actix/actix-web
File: src/httprequest.rs (Rust)

Code before:
            .finish_with_router(router);

        assert_eq!(
            req.url_for("unknown", &["test"]),
            Err(UrlGenerationError::ResourceNotFound)
        );
        assert_eq!(
            req.url_for("index", &["test"]),
            Err(UrlGenerationError::NotEnoughElements)
        );
        let url = req.url_for("index", &["test", "html"]);
        assert_eq!(
            url.ok().unwrap().as_str(),
            "http://www.rust-lang.org/user/test.html"
        );
    }

    #[test]
    fn test_url_for_with_prefix() {
        let mut resource = ResourceHandler::<()>::default();
        resource.name("index");
        let routes = vec![(Resource::new("index", "/user/{name}.html"), Some(resource))];
        let (router, _) = Router::new("/prefix/", routes);
        let info = router.default_route_info();
        assert!(info.has_route("/user/test.html"));
        assert!(info.has_prefixed_route("/user/test.html"));
        assert!(!info.has_route("/prefix/user/test.html"));
        assert!(info.has_prefixed_route("/prefix/user/test.html"));

        let req = TestRequest::with_header(header::HOST, "www.rust-lang.org")
            .finish_with_router(router);
        let url = req.url_for("index", &["test"]);
        assert_eq!(
            url.ok().unwrap().as_str(),
            "http://www.rust-lang.org/prefix/user/test.html"
        );
    }

    #[test]
    fn test_url_for_static() {
        let mut resource = ResourceHandler::<()>::default();
        resource.name("index");
        let routes = vec![(Resource::new("index", "/index.html"), Some(resource))];
        let (router, _) = Router::new("/prefix/", routes);
        let info = router.default_route_info();
        assert!(info.has_route("/index.html"));
        assert!(info.has_prefixed_route("/index.html"));
        assert!(!info.has_route("/prefix/index.html"));
        assert!(info.has_prefixed_route("/prefix/index.html"));

        let req = TestRequest::default()

Review comment (suggestion):
In continuation from our discussion.
The current behavior makes method is confusing.

It matches both route with prefix or without prefix.

I think this behavior makes it confusing and it should match only in one fashion:
Match both prefix and path.
If prefix is missing from route, then match only against path.

If provides path missing prefix, then it cannot match route, this makes the function name `has_prefixed_route` corresponding to what it actually does.

It is not clear what is benefit matching path against route but ignoring prefix, if path doesn't contain it?

P.s. sorry that I'm being persistent about it, but I just feel this API would be confusing in future

If @fafhrd91 is ok with it I don't mind

Code after:
        );
        assert_eq!(
            req.url_for("index", &["test"]),
            Err(UrlGenerationError::NotEnoughElements)
        );
        let url = req.url_for("index", &["test", "html"]);
        assert_eq!(
            url.ok().unwrap().as_str(),
            "http://www.rust-lang.org/user/test.html"
        );
    }

    #[test]
    fn test_url_for_with_prefix() {
        let mut resource = Resource::new(ResourceDef::new("/user/{name}.html"));
        resource.name("index");
        let mut router = Router::<()>::new();
        router.register_resource(resource);

        let mut info = router.default_route_info();
        info.set_prefix(7);
        assert!(info.has_route("/user/test.html"));
        assert!(!info.has_prefixed_route("/user/test.html"));
        assert!(!info.has_route("/prefix/user/test.html"));
        assert!(info.has_prefixed_route("/prefix/user/test.html"));

        let req = TestRequest::with_uri("/prefix/test")
            .prefix(7)
            .header(header::HOST, "www.rust-lang.org")
            .finish_with_router(router);
        let url = req.url_for("index", &["test"]);
        assert_eq!(
            url.ok().unwrap().as_str(),
            "http://www.rust-lang.org/prefix/user/test.html"
        );
    }

    #[test]
    fn test_url_for_static() {
        let mut resource = Resource::new(ResourceDef::new("/index.html"));
        resource.name("index");
        let mut router = Router::<()>::new();
        router.register_resource(resource);

        let mut info = router.default_route_info();
        info.set_prefix(7);
        assert!(info.has_route("/index.html"));
        assert!(!info.has_prefixed_route("/index.html"));
        assert!(!info.has_route("/prefix/index.html"));
        assert!(info.has_prefixed_route("/prefix/index.html"));