@@ -44,14 +44,14 @@ mod file;
44
44
mod builds;
45
45
mod error;
46
46
mod sitemap;
47
- mod opensearch;
48
47
49
48
use std:: env;
50
49
use std:: error:: Error ;
51
50
use std:: time:: Duration ;
52
51
use std:: path:: PathBuf ;
53
52
use iron:: prelude:: * ;
54
53
use iron:: { Handler , status} ;
54
+ use iron:: headers:: { CacheControl , CacheDirective , ContentType } ;
55
55
use router:: { Router , NoRoute } ;
56
56
use staticfile:: Static ;
57
57
use handlebars_iron:: { HandlebarsEngine , DirectorySource } ;
@@ -65,6 +65,7 @@ use std::collections::BTreeMap;
65
65
/// Duration of static files for staticfile and DatabaseFileHandler (in seconds)
66
66
const STATIC_FILE_CACHE_DURATION : u64 = 60 * 60 * 24 * 30 * 12 ; // 12 months
67
67
const STYLE_CSS : & ' static str = include_str ! ( concat!( env!( "OUT_DIR" ) , "/style.css" ) ) ;
68
+ const OPENSEARCH_XML : & ' static [ u8 ] = include_bytes ! ( "opensearch.xml" ) ;
68
69
69
70
70
71
struct CratesfyiHandler {
@@ -100,9 +101,7 @@ impl CratesfyiHandler {
100
101
"about" ) ;
101
102
router. get ( "/robots.txt" , sitemap:: robots_txt_handler, "robots_txt" ) ;
102
103
router. get ( "/sitemap.xml" , sitemap:: sitemap_handler, "sitemap_xml" ) ;
103
- router. get ( "/opensearch.xml" ,
104
- opensearch:: serve_opensearch,
105
- "opensearch_xml" ) ;
104
+ router. get ( "/opensearch.xml" , opensearch_xml_handler, "opensearch_xml" ) ;
106
105
router. get ( "/releases" , releases:: releases_handler, "releases" ) ;
107
106
router. get ( "/releases/feed" ,
108
107
releases:: releases_feed_handler,
@@ -395,7 +394,6 @@ fn duration_to_str(ts: time::Timespec) -> String {
395
394
396
395
397
396
fn style_css_handler ( _: & mut Request ) -> IronResult < Response > {
398
- use iron:: headers:: { CacheControl , CacheDirective , ContentType } ;
399
397
let mut response = Response :: with ( ( status:: Ok , STYLE_CSS ) ) ;
400
398
let cache = vec ! [ CacheDirective :: Public ,
401
399
CacheDirective :: MaxAge ( STATIC_FILE_CACHE_DURATION as u32 ) ] ;
@@ -405,6 +403,16 @@ fn style_css_handler(_: &mut Request) -> IronResult<Response> {
405
403
}
406
404
407
405
406
+ fn opensearch_xml_handler ( _: & mut Request ) -> IronResult < Response > {
407
+ let mut response = Response :: with ( ( status:: Ok , OPENSEARCH_XML ) ) ;
408
+ let cache = vec ! [ CacheDirective :: Public ,
409
+ CacheDirective :: MaxAge ( STATIC_FILE_CACHE_DURATION as u32 ) ] ;
410
+ response. headers . set ( ContentType ( "application/opensearchdescription+xml" . parse ( ) . unwrap ( ) ) ) ;
411
+ response. headers . set ( CacheControl ( cache) ) ;
412
+ Ok ( response)
413
+ }
414
+
415
+
408
416
/// MetaData used in header
409
417
#[ derive( Debug ) ]
410
418
pub struct MetaData {
0 commit comments