Implement dual host configuration: bind_host and hostname
- Replace 'host' config with separate 'bind_host' and 'hostname' - bind_host: IP/interface for server binding (default 0.0.0.0) - hostname: Domain for URI validation (required) - Update all parsing and validation code - Create dist/ directory with systemd service, config, and install guide - Add comprehensive INSTALL.md with setup instructions
This commit is contained in:
parent
1665df65da
commit
ea8083fe1f
7 changed files with 333 additions and 13 deletions
14
src/main.rs
14
src/main.rs
|
|
@ -52,7 +52,8 @@ async fn main() {
|
|||
root: None,
|
||||
cert: None,
|
||||
key: None,
|
||||
host: None,
|
||||
bind_host: None,
|
||||
hostname: None,
|
||||
port: None,
|
||||
log_level: None,
|
||||
max_concurrent_requests: None,
|
||||
|
|
@ -66,7 +67,8 @@ async fn main() {
|
|||
let root = config.root.expect("root is required");
|
||||
let cert_path = config.cert.expect("cert is required");
|
||||
let key_path = config.key.expect("key is required");
|
||||
let host = config.host.unwrap_or_else(|| "0.0.0.0".to_string());
|
||||
let bind_host = config.bind_host.unwrap_or_else(|| "0.0.0.0".to_string());
|
||||
let hostname = config.hostname.expect("hostname is required");
|
||||
let port = config.port.unwrap_or(1965);
|
||||
|
||||
// Validate max concurrent requests
|
||||
|
|
@ -104,22 +106,22 @@ async fn main() {
|
|||
|
||||
let acceptor = TlsAcceptor::from(Arc::new(config));
|
||||
|
||||
let listener = TcpListener::bind(format!("{}:{}", host, port)).await.unwrap();
|
||||
let listener = TcpListener::bind(format!("{}:{}", bind_host, port)).await.unwrap();
|
||||
|
||||
// Print startup information
|
||||
print_startup_info(&host, port, &root, &cert_path, &key_path, Some(log_level), max_concurrent_requests);
|
||||
print_startup_info(&bind_host, port, &root, &cert_path, &key_path, Some(log_level), max_concurrent_requests);
|
||||
|
||||
loop {
|
||||
let (stream, _) = listener.accept().await.unwrap();
|
||||
tracing::debug!("Accepted connection from {}", stream.peer_addr().unwrap_or_else(|_| "unknown".parse().unwrap()));
|
||||
let acceptor = acceptor.clone();
|
||||
let dir = root.clone();
|
||||
let expected_host = "localhost".to_string(); // Override for testing
|
||||
let expected_hostname = hostname.clone(); // Use configured hostname
|
||||
let max_concurrent = max_concurrent_requests;
|
||||
let test_delay = test_processing_delay;
|
||||
tokio::spawn(async move {
|
||||
if let Ok(stream) = acceptor.accept(stream).await {
|
||||
if let Err(e) = server::handle_connection(stream, &dir, &expected_host, port, max_concurrent, test_delay).await {
|
||||
if let Err(e) = server::handle_connection(stream, &dir, &expected_hostname, port, max_concurrent, test_delay).await {
|
||||
tracing::error!("Error handling connection: {}", e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue