Repository: static-web-server/static-web-server (language: rust)

Issue:
add virtual host domain to logging
### Search for duplicate feature request

- [X] I already searched, and this feature request or improvement is not a duplicate.

### Feature scope

Improve existing functionality

### Feature request related to a problem

_No response_

### Describe the solution you'd like

I have installed sws and it works fine for virtual hosts domains. 
Config is like so:
`
[[advanced.virtual-hosts]]
host = "www.hanscees.com"
root = "/var/hanscees"
` 

However, in the logging it is not discernable what domain the logs belong to. 
`
web-1  | 2024-03-01T22:03:40.848154Z  INFO static_web_server::handler: incoming request: method=GET uri=/img/slide-3.jpg remote_addr=[::ffff:192.168.0.2]:43484
`
Please consider adding something to the logging so it becomes clear what domain was involved

### Describe alternatives you've considered

non

### Build target

All targets

### Additional context

_No response_


Discussion / hints:

Fix patch:
diff --git a/src/handler.rs b/src/handler.rs
index 3c113c51..88ffa556 100644
--- a/src/handler.rs
+++ b/src/handler.rs
@@ -235,7 +235,7 @@ impl RequestHandler {
             if let Some(advanced) = &self.opts.advanced_opts {
                 // If the "Host" header matches any virtual_host, change the root directory
                 if let Some(root) =
-                    virtual_hosts::get_real_root(req.headers(), advanced.virtual_hosts.as_deref())
+                    virtual_hosts::get_real_root(req, advanced.virtual_hosts.as_deref())
                 {
                     base_path = root;
                 }
diff --git a/src/lib.rs b/src/lib.rs
index d6947849..900e0051 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -194,7 +194,7 @@ pub mod static_files;
 #[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
 pub mod tls;
 pub mod transport;
-pub mod virtual_hosts;
+pub(crate) mod virtual_hosts;
 #[cfg(windows)]
 #[cfg_attr(docsrs, doc(cfg(windows)))]
 pub mod winservice;
diff --git a/src/virtual_hosts.rs b/src/virtual_hosts.rs
index 3fc1acd6..c700c5a8 100644
--- a/src/virtual_hosts.rs
+++ b/src/virtual_hosts.rs
@@ -6,21 +6,28 @@
 //! Module that allows to determine a virtual hostname.
 //!
 
-use headers::HeaderMap;
 use hyper::header::HOST;
+use hyper::Request;
 use std::path::PathBuf;
 
 use crate::settings::VirtualHosts;
 
 /// It returns different root directory if the "Host" header matches a virtual hostname.
-pub fn get_real_root<'a>(
-    headers: &HeaderMap,
+pub(crate) fn get_real_root<'a, T>(
+    req: &mut Request<T>,
     vhosts_opts: Option<&'a [VirtualHosts]>,
 ) -> Option<&'a PathBuf> {
     if let Some(vhosts) = vhosts_opts {
-        if let Ok(host_str) = headers.get(HOST)?.to_str() {
+        if let Ok(host_str) = req.headers().get(HOST)?.to_str() {
             for vhost in vhosts {
                 if vhost.host == host_str {
+                    tracing::info!(
+                        "virtual host matched: vhost={} vhost_root={} method={} uri={}",
+                        vhost.host,
+                        vhost.root.display(),
+                        req.method(),
+                        req.uri(),
+                    );
                     return Some(&vhost.root);
                 }
             }


Test patch: