@@ -102,7 +102,7 @@ pub(crate) struct WorkerConfig {
102102 pub http1_opts : HTTP1Config ,
103103 pub http2_opts : HTTP2Config ,
104104 pub websockets_enabled : bool ,
105- pub static_files : Option < ( String , String , Option < String > ) > ,
105+ pub static_files : Option < ( String , String , Option < String > , Option < String > ) > ,
106106 pub tls_opts : Option < WorkerTlsConfig > ,
107107 pub metrics : (
108108 Option < std:: time:: Duration > ,
@@ -134,7 +134,7 @@ impl WorkerConfig {
134134 http1_opts : HTTP1Config ,
135135 http2_opts : HTTP2Config ,
136136 websockets_enabled : bool ,
137- static_files : Option < ( String , String , Option < String > ) > ,
137+ static_files : Option < ( String , String , Option < String > , Option < String > ) > ,
138138 ssl_enabled : bool ,
139139 ssl_cert : Option < String > ,
140140 ssl_key : Option < String > ,
@@ -266,21 +266,23 @@ pub(crate) struct WorkerCTXFiles<M> {
266266 pub metrics : M ,
267267 pub static_prefix : String ,
268268 pub static_mount : String ,
269+ pub static_dir_to_file : Option < String > ,
269270 pub static_expires : Option < String > ,
270271}
271272
272273impl < M > WorkerCTXFiles < M > {
273274 pub fn new (
274275 callback : crate :: callbacks:: PyCBScheduler ,
275276 metrics : M ,
276- files : Option < ( String , String , Option < String > ) > ,
277+ files : Option < ( String , String , Option < String > , Option < String > ) > ,
277278 ) -> Self {
278- let ( static_prefix, static_mount, static_expires) = files. unwrap ( ) ;
279+ let ( static_prefix, static_mount, static_dir_to_file , static_expires) = files. unwrap ( ) ;
279280 Self {
280281 callback : Arc :: new ( callback) ,
281282 metrics,
282283 static_prefix,
283284 static_mount,
285+ static_dir_to_file,
284286 static_expires,
285287 }
286288 }
@@ -402,9 +404,12 @@ macro_rules! service_impl {
402404 type Future = Pin <Box <dyn Future <Output = Result <Self :: Response , Self :: Error >> + Send >>;
403405
404406 fn call( & self , req: crate :: http:: HTTPRequest ) -> Self :: Future {
405- if let Some ( static_match) =
406- crate :: files:: match_static_file( req. uri( ) . path( ) , & self . ctx. static_prefix, & self . ctx. static_mount)
407- {
407+ if let Some ( static_match) = crate :: files:: match_static_file(
408+ req. uri( ) . path( ) ,
409+ & self . ctx. static_prefix,
410+ & self . ctx. static_mount,
411+ self . ctx. static_dir_to_file. as_ref( ) ,
412+ ) {
408413 if static_match. is_err( ) {
409414 return Box :: pin( async move { Ok :: <_, hyper:: Error >( crate :: http:: response_404( ) ) } ) ;
410415 }
@@ -477,9 +482,12 @@ macro_rules! service_impl {
477482 . req_handled
478483 . fetch_add( 1 , std:: sync:: atomic:: Ordering :: Release ) ;
479484
480- if let Some ( static_match) =
481- crate :: files:: match_static_file( req. uri( ) . path( ) , & self . ctx. static_prefix, & self . ctx. static_mount)
482- {
485+ if let Some ( static_match) = crate :: files:: match_static_file(
486+ req. uri( ) . path( ) ,
487+ & self . ctx. static_prefix,
488+ & self . ctx. static_mount,
489+ self . ctx. static_dir_to_file. as_ref( ) ,
490+ ) {
483491 self . ctx
484492 . metrics
485493 . req_static_handled
0 commit comments