Implement BACKLOG.md items: config-only, request limits, URL validation

- Remove CLI options except --config and --test-processing-delay
- Enforce 1026 byte request limit per Gemini spec (1024 + 2 for CRLF)
- Add comprehensive URL parsing with host and port validation
- Reject malformed URIs and wrong ports with 59 Bad Request
- Update tests for new URL parsing signature
- Fix clippy warning in port parsing
This commit is contained in:
Jeena 2026-01-16 11:48:06 +00:00
parent 6a61b562f5
commit f05b9373f1
3 changed files with 38 additions and 37 deletions

View file

@ -34,26 +34,6 @@ struct Args {
#[arg(short = 'C', long)]
config: Option<String>,
/// Directory to serve files from
#[arg(short, long)]
root: Option<String>,
/// Path to certificate file
#[arg(short, long)]
cert: Option<String>,
/// Path to private key file
#[arg(short, long)]
key: Option<String>,
/// Port to listen on
#[arg(short, long)]
port: Option<u16>,
/// Hostname for the server
#[arg(short = 'H', long)]
host: Option<String>,
/// TESTING ONLY: Add delay before processing (seconds) [debug builds only]
#[cfg(debug_assertions)]
#[arg(long, value_name = "SECONDS")]
@ -82,12 +62,12 @@ async fn main() {
let log_level = config.log_level.as_deref().unwrap_or("info");
init_logging(log_level);
// Merge config with args (args take precedence)
let root = args.root.or(config.root).expect("root is required");
let cert_path = args.cert.or(config.cert).expect("cert is required");
let key_path = args.key.or(config.key).expect("key is required");
let host = args.host.or(config.host).unwrap_or_else(|| "0.0.0.0".to_string());
let port = args.port.or(config.port).unwrap_or(1965);
// Load configuration from file only
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 port = config.port.unwrap_or(1965);
// Validate max concurrent requests
let max_concurrent_requests = config.max_concurrent_requests.unwrap_or(1000);
@ -139,7 +119,7 @@ async fn main() {
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, max_concurrent, test_delay).await {
if let Err(e) = server::handle_connection(stream, &dir, &expected_host, port, max_concurrent, test_delay).await {
tracing::error!("Error handling connection: {}", e);
}
}