File tree Expand file tree Collapse file tree 2 files changed +27
-5
lines changed Expand file tree Collapse file tree 2 files changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -103,7 +103,14 @@ impl CratesfyiHandler {
103103 router. get ( "/robots.txt" , sitemap:: robots_txt_handler, "robots_txt" ) ;
104104 router. get ( "/sitemap.xml" , sitemap:: sitemap_handler, "sitemap_xml" ) ;
105105 router. get ( "/opensearch.xml" , opensearch_xml_handler, "opensearch_xml" ) ;
106- router. get ( "/std" , rustdoc:: std_redirector_handler, "std" ) ;
106+
107+ // Redirect standard library crates to rust-lang.org
108+ router. get ( "/alloc" , rustdoc:: RustLangRedirector :: new ( "alloc" ) , "alloc" ) ;
109+ router. get ( "/core" , rustdoc:: RustLangRedirector :: new ( "core" ) , "core" ) ;
110+ router. get ( "/proc_macro" , rustdoc:: RustLangRedirector :: new ( "proc_macro" ) , "proc_macro" ) ;
111+ router. get ( "/std" , rustdoc:: RustLangRedirector :: new ( "std" ) , "std" ) ;
112+ router. get ( "/test" , rustdoc:: RustLangRedirector :: new ( "test" ) , "test" ) ;
113+
107114 router. get ( "/releases" , releases:: recent_releases_handler, "releases" ) ;
108115 router. get ( "/releases/feed" ,
109116 releases:: releases_feed_handler,
Original file line number Diff line number Diff line change @@ -65,11 +65,26 @@ impl ToJson for RustdocPage {
6565 }
6666}
6767
68+ pub struct RustLangRedirector {
69+ target : & ' static str ,
70+ }
6871
69- /// Handler called for the `/std`. Redirects to the official standard library docs.
70- pub fn std_redirector_handler ( _req : & mut Request ) -> IronResult < Response > {
71- let url = Url :: parse ( "https://doc.rust-lang.org/stable/std/" ) . unwrap ( ) ;
72- Ok ( Response :: with ( ( status:: Found , Redirect ( url) ) ) )
72+ impl RustLangRedirector {
73+ 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 > {
80+ let url = url:: Url :: parse ( "https://doc.rust-lang.org/stable/" )
81+ . expect ( "failed to parse rust-lang.org base URL" )
82+ . join ( self . target )
83+ . expect ( "failed to append crate name to rust-lang.org base URL" ) ;
84+ let url = Url :: from_generic_url ( url)
85+ . expect ( "failed to convert url::Url to iron::Url" ) ;
86+ Ok ( Response :: with ( ( status:: Found , Redirect ( url) ) ) )
87+ }
7388}
7489
7590/// Handler called for `/:crate` and `/:crate/:version` URLs. Automatically redirects to the docs
You can’t perform that action at this time.
0 commit comments