Skip to content

Commit d29b3b8

Browse files
Merge pull request #456 from fusion-engineering-forks/rustlang-redirector-parse-once
Parse URL for rustlang.org redirector once.
2 parents 992c7e2 + 41ec5f3 commit d29b3b8

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/web/rustdoc.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,24 @@ impl ToJson for RustdocPage {
6666
}
6767

6868
pub struct RustLangRedirector {
69-
target: &'static str,
69+
url: Url,
7070
}
7171

7272
impl RustLangRedirector {
7373
pub fn new(target: &'static str) -> Self {
74-
Self { target }
75-
}
76-
}
77-
78-
impl iron::Handler for RustLangRedirector {
79-
fn handle(&self, _req: &mut Request) -> IronResult<Response> {
8074
let url = url::Url::parse("https://doc.rust-lang.org/stable/")
8175
.expect("failed to parse rust-lang.org base URL")
82-
.join(self.target)
76+
.join(target)
8377
.expect("failed to append crate name to rust-lang.org base URL");
8478
let url = Url::from_generic_url(url)
8579
.expect("failed to convert url::Url to iron::Url");
86-
Ok(Response::with((status::Found, Redirect(url))))
80+
Self { url }
81+
}
82+
}
83+
84+
impl iron::Handler for RustLangRedirector {
85+
fn handle(&self, _req: &mut Request) -> IronResult<Response> {
86+
Ok(Response::with((status::Found, Redirect(self.url.clone()))))
8787
}
8888
}
8989

0 commit comments

Comments
 (0)