feat: Implement virtual hosting for multi-domain Gemini server
- Add hostname-based request routing for multiple capsules per server - Parse virtual host configs from TOML sections ([hostname]) - Implement per-host certificate and content isolation - Add comprehensive virtual host testing and validation - Update docs and examples for multi-host deployments This enables Pollux to serve multiple Gemini domains from one instance, providing the foundation for multi-tenant Gemini hosting.
This commit is contained in:
parent
c193d831ed
commit
0459cb6220
22 changed files with 2296 additions and 406 deletions
|
|
@ -7,15 +7,22 @@ fn test_rate_limiting_with_concurrent_requests() {
|
|||
|
||||
// Create config with rate limiting enabled
|
||||
let config_path = temp_dir.path().join("config.toml");
|
||||
|
||||
// Use existing content directory and cert files from setup_test_environment
|
||||
let root_dir = temp_dir.path().join("content");
|
||||
let cert_path = temp_dir.path().join("cert.pem");
|
||||
let key_path = temp_dir.path().join("key.pem");
|
||||
|
||||
let config_content = format!(r#"
|
||||
root = "{}"
|
||||
cert = "{}"
|
||||
key = "{}"
|
||||
hostname = "localhost"
|
||||
bind_host = "127.0.0.1"
|
||||
port = {}
|
||||
max_concurrent_requests = 1
|
||||
"#, temp_dir.path().join("content").display(), temp_dir.path().join("cert.pem").display(), temp_dir.path().join("key.pem").display(), port);
|
||||
bind_host = "127.0.0.1"
|
||||
port = {}
|
||||
max_concurrent_requests = 1
|
||||
|
||||
["localhost"]
|
||||
root = "{}"
|
||||
cert = "{}"
|
||||
key = "{}"
|
||||
"#, port, root_dir.display(), cert_path.display(), key_path.display());
|
||||
std::fs::write(&config_path, config_content).unwrap();
|
||||
|
||||
// Start server binary with test delay to simulate processing time
|
||||
|
|
@ -23,7 +30,7 @@ fn test_rate_limiting_with_concurrent_requests() {
|
|||
.arg("--config")
|
||||
.arg(&config_path)
|
||||
.arg("--test-processing-delay")
|
||||
.arg("1") // 1 second delay per request
|
||||
.arg("3") // 3 second delay per request
|
||||
.spawn()
|
||||
.expect("Failed to start server");
|
||||
|
||||
|
|
@ -33,11 +40,13 @@ fn test_rate_limiting_with_concurrent_requests() {
|
|||
// Spawn 5 concurrent client processes
|
||||
let mut handles = vec![];
|
||||
for _ in 0..5 {
|
||||
let url = format!("gemini://localhost:{}/test.gmi", port);
|
||||
let url = format!("gemini://localhost/test.gmi");
|
||||
let handle = std::thread::spawn(move || {
|
||||
std::process::Command::new("python3")
|
||||
.arg("tests/gemini_test_client.py")
|
||||
.arg(url)
|
||||
.env("GEMINI_PORT", &port.to_string())
|
||||
.env("RATE_LIMIT_TEST", "true")
|
||||
.output()
|
||||
});
|
||||
handles.push(handle);
|
||||
|
|
@ -58,8 +67,14 @@ fn test_rate_limiting_with_concurrent_requests() {
|
|||
let success_count = results.iter().filter(|r| r.starts_with("20")).count();
|
||||
let rate_limited_count = results.iter().filter(|r| r.starts_with("41")).count();
|
||||
|
||||
// Validation
|
||||
assert!(success_count >= 1, "At least 1 request should succeed, got results: {:?}", results);
|
||||
assert!(rate_limited_count >= 1, "At least 1 request should be rate limited, got results: {:?}", results);
|
||||
assert_eq!(success_count + rate_limited_count, 5, "All requests should get valid responses, got results: {:?}", results);
|
||||
// Debug output
|
||||
println!("Results: {:?}", results);
|
||||
println!("Success: {}, Rate limited: {}", success_count, rate_limited_count);
|
||||
|
||||
// Strict validation - rate limiting must work deterministically with delay
|
||||
assert_eq!(success_count, 1, "Expected exactly 1 successful request with limit=1, got {}. Results: {:?}", success_count, results);
|
||||
assert_eq!(rate_limited_count, 4, "Expected exactly 4 rate limited requests with limit=1, got {}. Results: {:?}", rate_limited_count, results);
|
||||
|
||||
// Verify all requests received valid responses
|
||||
assert_eq!(success_count + rate_limited_count, 5, "All 5 requests should receive responses. Results: {:?}", results);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue