@@ -76,6 +76,7 @@ impl ServeDir<DefaultServeDirFallback> {
76
76
precompressed_variants : None ,
77
77
variant : ServeVariant :: Directory {
78
78
append_index_html_on_directories : true ,
79
+ html_as_default_extension : true ,
79
80
} ,
80
81
fallback : None ,
81
82
call_fallback_on_method_not_allowed : false ,
@@ -105,16 +106,27 @@ impl<F> ServeDir<F> {
105
106
/// Defaults to `true`.
106
107
pub fn append_index_html_on_directories ( mut self , append : bool ) -> Self {
107
108
match & mut self . variant {
108
- ServeVariant :: Directory {
109
- append_index_html_on_directories,
110
- } => {
109
+ ServeVariant :: Directory { append_index_html_on_directories, .. } => {
111
110
* append_index_html_on_directories = append;
112
111
self
113
112
}
114
113
ServeVariant :: SingleFile { mime : _ } => self ,
115
114
}
116
115
}
117
116
117
+ /// If the requested path doesn't specify a file extension, append `.html`.
118
+ ///
119
+ /// Defaults to `true`.
120
+ pub fn html_as_default_extension ( mut self , append : bool ) -> Self {
121
+ match & mut self . variant {
122
+ ServeVariant :: Directory { html_as_default_extension, .. } => {
123
+ * html_as_default_extension = append;
124
+ self
125
+ }
126
+ ServeVariant :: SingleFile { mime : _ } => self ,
127
+ }
128
+ }
129
+
118
130
/// Set a specific read buffer chunk size.
119
131
///
120
132
/// The default capacity is 64kb.
@@ -443,6 +455,7 @@ opaque_future! {
443
455
enum ServeVariant {
444
456
Directory {
445
457
append_index_html_on_directories : bool ,
458
+ html_as_default_extension : bool ,
446
459
} ,
447
460
SingleFile {
448
461
mime : HeaderValue ,
@@ -454,6 +467,7 @@ impl ServeVariant {
454
467
match self {
455
468
ServeVariant :: Directory {
456
469
append_index_html_on_directories : _,
470
+ html_as_default_extension : _,
457
471
} => {
458
472
let path = requested_path. trim_start_matches ( '/' ) ;
459
473
0 commit comments