File tree Expand file tree Collapse file tree 2 files changed +14
-9
lines changed Expand file tree Collapse file tree 2 files changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -491,15 +491,7 @@ async fn peek_mime(file: &mut async_std::fs::File) -> io::Result<Option<Mime>> {
491
491
#[ cfg( all( feature = "async_std" , not( target_os = "unknown" ) ) ) ]
492
492
fn guess_ext ( path : & std:: path:: Path ) -> Option < Mime > {
493
493
let ext = path. extension ( ) . map ( |p| p. to_str ( ) ) . flatten ( ) ;
494
- match ext {
495
- Some ( "html" ) => Some ( mime:: HTML ) ,
496
- Some ( "js" ) | Some ( "mjs" ) | Some ( "jsonp" ) => Some ( mime:: JAVASCRIPT ) ,
497
- Some ( "json" ) => Some ( mime:: JSON ) ,
498
- Some ( "css" ) => Some ( mime:: CSS ) ,
499
- Some ( "svg" ) => Some ( mime:: SVG ) ,
500
- Some ( "xml" ) => Some ( mime:: XML ) ,
501
- None | Some ( _) => None ,
502
- }
494
+ ext. and_then ( Mime :: from_extension)
503
495
}
504
496
505
497
#[ cfg( test) ]
Original file line number Diff line number Diff line change @@ -50,6 +50,19 @@ impl Mime {
50
50
Mime :: from_str ( & mime)
51
51
}
52
52
53
+ /// Guess the mime type from a file extension
54
+ pub fn from_extension ( extension : impl AsRef < str > ) -> Option < Self > {
55
+ match extension. as_ref ( ) {
56
+ "html" => Some ( HTML ) ,
57
+ "js" | "mjs" | "jsonp" => Some ( JAVASCRIPT ) ,
58
+ "json" => Some ( JSON ) ,
59
+ "css" => Some ( CSS ) ,
60
+ "svg" => Some ( SVG ) ,
61
+ "xml" => Some ( XML ) ,
62
+ _ => None ,
63
+ }
64
+ }
65
+
53
66
/// Access the Mime's `type` value.
54
67
///
55
68
/// According to the spec this method should be named `type`, but that's a reserved keyword in
You can’t perform that action at this time.
0 commit comments