@@ -70,14 +70,15 @@ impl Config {
7070
7171 fn load_file ( path : & Path ) -> Result < Self , ConfigLoadError > {
7272 let mut fragment = ConfigFragment :: load ( path) ?;
73+ let include_conf_d = fragment. include_conf_d ;
7374 let parent = path. parent ( ) ;
7475 if let Some ( parent) = parent {
7576 fragment. resolve_relative_paths ( parent) ;
7677 }
7778
7879 let mut config = Self :: default ( ) ;
7980 config. merge ( fragment) ;
80- if let Some ( parent) = parent {
81+ if include_conf_d && let Some ( parent) = parent {
8182 config. merge_conf_d ( parent) ?;
8283 }
8384 Ok ( config)
@@ -225,6 +226,8 @@ impl Config {
225226#[ derive( Debug , Clone , Default , Eq , PartialEq , Deserialize , Serialize ) ]
226227#[ serde( deny_unknown_fields) ]
227228struct ConfigFragment {
229+ #[ serde( default ) ]
230+ include_conf_d : bool ,
228231 #[ serde( default ) ]
229232 server : Option < ServerConfigFragment > ,
230233 #[ serde( default ) ]
@@ -7065,6 +7068,8 @@ mod tests {
70657068 fs:: write (
70667069 dir. child ( "fluxheim.toml" ) ,
70677070 r#"
7071+ include_conf_d = true
7072+
70687073 [server]
70697074 listen = ["127.0.0.1:19090"]
70707075 default_vhost = "example"
@@ -7091,6 +7096,33 @@ mod tests {
70917096 assert_eq ! ( config. vhosts[ 0 ] . web. root, Some ( dir. child( "conf.d/site" ) ) ) ;
70927097 }
70937098
7099+ #[ test]
7100+ fn loading_main_config_file_does_not_load_conf_d_without_opt_in ( ) {
7101+ let dir = TestDir :: new ( "config-file-with-conf-d-no-opt-in" ) ;
7102+ fs:: create_dir_all ( dir. child ( "conf.d" ) ) . unwrap ( ) ;
7103+ fs:: write (
7104+ dir. child ( "fluxheim.toml" ) ,
7105+ r#"
7106+ [server]
7107+ listen = ["127.0.0.1:19090"]
7108+ "# ,
7109+ )
7110+ . unwrap ( ) ;
7111+ fs:: write (
7112+ dir. child ( "conf.d/10-vhost.toml" ) ,
7113+ r#"
7114+ [[vhosts]]
7115+ name = "example"
7116+ hosts = ["example.test"]
7117+ "# ,
7118+ )
7119+ . unwrap ( ) ;
7120+
7121+ let config = Config :: load ( Some ( & dir. child ( "fluxheim.toml" ) ) ) . unwrap ( ) ;
7122+
7123+ assert ! ( config. vhosts. is_empty( ) ) ;
7124+ }
7125+
70947126 #[ test]
70957127 fn loading_config_directory_also_loads_conf_d_after_top_level_files ( ) {
70967128 let dir = TestDir :: new ( "config-dir-with-conf-d" ) ;
0 commit comments