@@ -111,25 +111,41 @@ pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult<Response> {
111
111
112
112
pub fn rustdoc_html_server_handler ( req : & mut Request ) -> IronResult < Response > {
113
113
114
- let path = {
115
- let mut path = req. url . path . clone ( ) ;
116
- // documentations have "rustdoc" prefix in database
117
- path. insert ( 0 , "rustdoc" . to_owned ( ) ) ;
114
+ let name = req. extensions . get :: < Router > ( ) . unwrap ( ) . find ( "crate" ) . unwrap_or ( "" ) . to_string ( ) ;
115
+ let version = req. extensions
116
+ . get :: < Router > ( )
117
+ . unwrap ( )
118
+ . find ( "version" ) ;
119
+ let conn = req. extensions . get :: < Pool > ( ) . unwrap ( ) ;
120
+ let version = try!( match_version ( & conn, & name, version)
121
+ . ok_or ( IronError :: new ( Nope :: ResourceNotFound , status:: NotFound ) ) ) ;
122
+
123
+ // remove name and version from path
124
+ for _ in 0 ..2 {
125
+ req. url . path . remove ( 0 ) ;
126
+ }
127
+
128
+ // docs have "rustdoc" prefix in database
129
+ req. url . path . insert ( 0 , "rustdoc" . to_owned ( ) ) ;
130
+
131
+ // add crate name and version
132
+ req. url . path . insert ( 1 , name. clone ( ) ) ;
133
+ req. url . path . insert ( 2 , version. clone ( ) ) ;
118
134
119
- let mut path = path. join ( "/" ) ;
135
+ let path = {
136
+ let mut path = req. url . path . join ( "/" ) ;
120
137
if path. ends_with ( "/" ) {
121
- path. push_str ( "index.html" )
138
+ path. push_str ( "index.html" ) ;
139
+ req. url . path . push ( "index.html" . to_owned ( ) ) ;
122
140
}
123
-
124
141
path
125
142
} ;
126
-
143
+
127
144
// don't touch anything other than html files
128
145
if !path. ends_with ( ".html" ) {
129
146
return Err ( IronError :: new ( Nope :: ResourceNotFound , status:: NotFound ) ) ;
130
147
}
131
148
132
- let conn = req. extensions . get :: < Pool > ( ) . unwrap ( ) ;
133
149
134
150
let file = match File :: from_path ( & conn, & path) {
135
151
Some ( f) => f,
@@ -165,15 +181,6 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
165
181
}
166
182
}
167
183
168
-
169
- let name = req. extensions . get :: < Router > ( ) . unwrap ( ) . find ( "crate" ) . unwrap_or ( "" ) . to_string ( ) ;
170
- let version = req. extensions
171
- . get :: < Router > ( )
172
- . unwrap ( )
173
- . find ( "version" )
174
- . unwrap_or ( "" )
175
- . to_string ( ) ;
176
-
177
184
// content.metadata = MetaData::from_crate(&conn, &name, &version);
178
185
let ( metadata, platforms) = {
179
186
let rows = conn. query ( "SELECT crates.name,
0 commit comments