virtual_hosts_module/configuration.rs
1// Copyright 2024 Wladimir Palant
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use module_utils::merge_conf;
16use serde::Deserialize;
17use std::collections::HashMap;
18
19/// Additional configuration settings for a subdirectory
20#[derive(Debug, Default, Deserialize)]
21#[serde(default)]
22pub struct SubDirConf {
23 /// If `true`, subdirectory will be removed from the URI before passing it on to the handler.
24 pub strip_prefix: bool,
25}
26
27/// Combined configuration structure for virtual hosts
28///
29/// This merges the settings from both member fields via `serde(flatten)`.
30#[merge_conf]
31pub struct SubDirCombined<C: Default> {
32 /// Subdirectory specific settings
33 pub subdir: SubDirConf,
34 /// Generic handler settings
35 pub config: C,
36}
37
38/// Additional configuration settings for a virtual host
39#[derive(Debug, Default, Deserialize)]
40#[serde(default)]
41pub struct VirtualHostConf<C: Default> {
42 /// List of additional names for the virtual host
43 pub aliases: Vec<String>,
44 /// If true, this virtual host should be used as fallback when no other virtual host
45 /// configuration applies
46 pub default: bool,
47 /// Maps virtual host's subdirectories to their special configurations
48 pub subdirs: HashMap<String, SubDirCombined<C>>,
49}
50
51/// Combined configuration structure for virtual hosts
52///
53/// This merges the settings from both member fields via `serde(flatten)`.
54#[merge_conf]
55pub struct VirtualHostCombined<C: Default> {
56 /// Virtual host specific settings
57 pub host: VirtualHostConf<C>,
58 /// Generic handler settings
59 pub config: C,
60}
61
62/// Virtual hosts configuration
63#[derive(Debug, Default, Deserialize)]
64#[serde(default)]
65pub struct VirtualHostsConf<C: Default> {
66 /// Maps virtual host names to their configuration
67 pub vhosts: HashMap<String, VirtualHostCombined<C>>,
68}