From 41ec5f347471432e244c42a6dd1c794f42c385a4 Mon Sep 17 00:00:00 2001 From: Maarten de Vries Date: Wed, 30 Oct 2019 22:02:40 +0100 Subject: [PATCH] Parse URL for rustlang.org redirector once. --- src/web/rustdoc.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/web/rustdoc.rs b/src/web/rustdoc.rs index e5d290c1e..b61a0a0db 100644 --- a/src/web/rustdoc.rs +++ b/src/web/rustdoc.rs @@ -66,24 +66,24 @@ impl ToJson for RustdocPage { } pub struct RustLangRedirector { - target: &'static str, + url: Url, } impl RustLangRedirector { pub fn new(target: &'static str) -> Self { - Self { target } - } -} - -impl iron::Handler for RustLangRedirector { - fn handle(&self, _req: &mut Request) -> IronResult { let url = url::Url::parse("https://doc.rust-lang.org/stable/") .expect("failed to parse rust-lang.org base URL") - .join(self.target) + .join(target) .expect("failed to append crate name to rust-lang.org base URL"); let url = Url::from_generic_url(url) .expect("failed to convert url::Url to iron::Url"); - Ok(Response::with((status::Found, Redirect(url)))) + Self { url } + } +} + +impl iron::Handler for RustLangRedirector { + fn handle(&self, _req: &mut Request) -> IronResult { + Ok(Response::with((status::Found, Redirect(self.url.clone())))) } }