Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/web/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response> {
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<Response> {
Ok(Response::with((status::Found, Redirect(self.url.clone()))))
}
}

Expand Down