@@ -15,6 +15,7 @@ use super::page::Page;
15
15
use rustc_serialize:: json:: { Json , ToJson } ;
16
16
use std:: collections:: BTreeMap ;
17
17
use iron:: headers:: { Expires , HttpDate , CacheControl , CacheDirective } ;
18
+ use postgres:: Connection ;
18
19
use time;
19
20
use iron:: Handler ;
20
21
use utils;
@@ -260,32 +261,11 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
260
261
261
262
content. full = file_content;
262
263
let crate_details = cexpect ! ( CrateDetails :: new( & conn, & name, & version) ) ;
263
- let latest_version = latest_version ( & crate_details. versions , & version) ;
264
-
265
- let ( path, version) = if let Some ( version) = latest_version {
264
+ let ( path, version) = if let Some ( version) = latest_version ( & crate_details. versions , & version) {
266
265
req_path[ 2 ] = & version;
267
- let path = if File :: from_path ( & conn, & req_path. join ( "/" ) ) . is_some ( ) {
268
- req_path[ 3 ..] . join ( "/" ) // NOTE: this adds 'index.html' if it wasn't there before
269
- } else { // this page doesn't exist in the latest version
270
- let search_item = if * req_path. last ( ) . unwrap ( ) == "index.html" { // this is a module
271
- req_path[ & req_path. len ( ) - 2 ]
272
- } else { // this is an item
273
- req_path. last ( ) . unwrap ( ) . split ( '.' ) . nth ( 1 )
274
- . expect ( "paths should be of the form <class>.<name>.html" )
275
- } ;
276
- // check if req_path[3] is the platform choice or the name of the crate
277
- let concat_path;
278
- let crate_root = if req_path[ 3 ] != crate_details. target_name {
279
- concat_path = format ! ( "{}/{}" , req_path[ 3 ] , req_path[ 4 ] ) ;
280
- & concat_path
281
- } else {
282
- req_path[ 3 ]
283
- } ;
284
- format ! ( "{}/?search={}" , crate_root, search_item)
285
- } ;
286
- ( path, version)
266
+ ( path_for_version ( & req_path, & crate_details. target_name , & conn) , version)
287
267
} else {
288
- ( String :: new ( ) , String :: new ( ) )
268
+ Default :: default ( )
289
269
} ;
290
270
291
271
content. crate_details = Some ( crate_details) ;
@@ -300,7 +280,27 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
300
280
. to_resp ( "rustdoc" )
301
281
}
302
282
303
-
283
+ fn path_for_version ( req_path : & [ & str ] , target_name : & str , conn : & Connection ) -> String {
284
+ if File :: from_path ( & conn, & req_path. join ( "/" ) ) . is_some ( ) {
285
+ req_path[ 3 ..] . join ( "/" ) // NOTE: this adds 'index.html' if it wasn't there before
286
+ } else { // this page doesn't exist in the latest version
287
+ let search_item = if * req_path. last ( ) . unwrap ( ) == "index.html" { // this is a module
288
+ req_path[ req_path. len ( ) - 2 ]
289
+ } else { // this is an item
290
+ req_path. last ( ) . unwrap ( ) . split ( '.' ) . nth ( 1 )
291
+ . expect ( "paths should be of the form <class>.<name>.html" )
292
+ } ;
293
+ // check if req_path[3] is the platform choice or the name of the crate
294
+ let concat_path;
295
+ let crate_root = if req_path[ 3 ] != target_name {
296
+ concat_path = format ! ( "{}/{}" , req_path[ 3 ] , req_path[ 4 ] ) ;
297
+ & concat_path
298
+ } else {
299
+ req_path[ 3 ]
300
+ } ;
301
+ format ! ( "{}/?search={}" , crate_root, search_item)
302
+ }
303
+ }
304
304
305
305
pub fn badge_handler ( req : & mut Request ) -> IronResult < Response > {
306
306
use iron:: headers:: ContentType ;
0 commit comments