Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ name = "proxy_bench"
harness = false

[features]
default = ["cli", "tls", "api"]
default = ["cli", "tls", "api", "logging"]
cli = ["dep:clap", "dep:tracing-subscriber"]
tls = ["dep:hyper-rustls"]
api = ["dep:serde", "dep:serde_json"]
logging = []
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ cargo run --example background
- ⏳ TLS/SSL support
- ⏳ WebSocket support
- ⏳ Rate limiting
- Request/response logging
- ✅ Structured access log with X-Request-ID (method, path, host, status, duration, bytes_sent)
- ⏳ Metrics and monitoring

## Contributing
Expand Down
20 changes: 10 additions & 10 deletions src/api/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ where
.status(200)
.header("Content-Type", "application/json")
.body(Full::new(Bytes::from(json)))
.unwrap();
.expect("static response build");

Ok(response)
}
Expand Down Expand Up @@ -74,9 +74,9 @@ where
.status(400)
.header("Content-Type", "application/json")
.body(Full::new(Bytes::from(
serde_json::to_string(&error_json).unwrap(),
serde_json::to_string(&error_json).expect("json!() is always valid"),
)))
.unwrap();
.expect("static response build");
return Ok(response);
}
};
Expand All @@ -92,9 +92,9 @@ where
.status(400)
.header("Content-Type", "application/json")
.body(Full::new(Bytes::from(
serde_json::to_string(&error_json).unwrap(),
serde_json::to_string(&error_json).expect("json!() is always valid"),
)))
.unwrap();
.expect("static response build");
return Ok(response);
}
};
Expand All @@ -112,9 +112,9 @@ where
.status(400)
.header("Content-Type", "application/json")
.body(Full::new(Bytes::from(
serde_json::to_string(&error_json).unwrap(),
serde_json::to_string(&error_json).expect("json!() is always valid"),
)))
.unwrap();
.expect("static response build");
return Ok(response);
}
};
Expand All @@ -136,7 +136,7 @@ where
.body(Full::new(Bytes::from(
r#"{"status": "success", "message": "Configuration updated"}"#.to_string(),
)))
.unwrap();
.expect("static response build");

Ok(response)
}
Expand All @@ -158,9 +158,9 @@ where
.status(200)
.header("Content-Type", "application/json")
.body(Full::new(Bytes::from(
serde_json::to_string(&health).unwrap(),
serde_json::to_string(&health).expect("json!() is always valid"),
)))
.unwrap();
.expect("static response build");

Ok(response)
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn unauthorized_response(message: &str) -> Response<Full<Bytes>> {
.status(StatusCode::UNAUTHORIZED)
.header("Content-Type", "application/json")
.body(Full::new(Bytes::from(body)))
.unwrap()
.expect("static response build")
}

/// Logging middleware
Expand Down
4 changes: 2 additions & 2 deletions src/api/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ async fn handle_api_request(
// 404 Not Found
let response = Response::builder()
.status(404)
.body(Full::new(bytes::Bytes::from("Not Found".to_string())))
.unwrap();
.body(Full::new(bytes::Bytes::from("Not Found")))
.expect("static response build");
Ok(response)
}
}
Expand Down
17 changes: 12 additions & 5 deletions src/config/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ impl FromStr for Config {
// 2. Handle closing brace
if line == "}" {
if directive_stack.len() > 1 {
let finished_directives = directive_stack.pop().unwrap();
let block_info = block_stack.pop().unwrap();
let finished_directives = directive_stack
.pop()
.expect("directive_stack has at least 2 elements");
let block_info = block_stack.pop().expect("block_stack has matching entry");

let completed_directive = match block_info.directive_type.as_str() {
"handle_path" => {
Expand Down Expand Up @@ -145,12 +147,14 @@ impl FromStr for Config {

directive_stack
.last_mut()
.unwrap()
.expect("directive_stack has parent after pop")
.push(completed_directive);
} else {
// Site block closed
if let Some(address) = current_site_address.take() {
let site_directives = directive_stack.pop().unwrap();
let site_directives = directive_stack
.pop()
.expect("site directive_stack is non-empty");
sites.insert(
address.clone(),
SiteConfig {
Expand Down Expand Up @@ -309,7 +313,10 @@ impl FromStr for Config {
}
};

directive_stack.last_mut().unwrap().push(directive);
directive_stack
.last_mut()
.expect("directive_stack is non-empty")
.push(directive);
}

Ok(Config { sites })
Expand Down
18 changes: 14 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async fn run_with_api(cli: Cli, config: Config) -> Result<(), anyhow::Error> {
// Wait for shutdown signal
tokio::select! {
// API server completed
api_result = async { api_handle.as_mut().unwrap().await } => {
api_result = async { api_handle.as_mut().expect("api_handle is Some").await } => {
match api_result {
Ok(Ok(())) => info!("API server shut down gracefully"),
Ok(Err(e)) => error!("API server error: {}", e),
Expand All @@ -120,7 +120,7 @@ async fn run_with_api(cli: Cli, config: Config) -> Result<(), anyhow::Error> {
let _ = shutdown_tx.send(());
},
// Proxy server completed
proxy_result = async { proxy_handle.as_mut().unwrap().await } => {
proxy_result = async { proxy_handle.as_mut().expect("proxy_handle is Some").await } => {
match proxy_result {
Ok(Ok(())) => info!("Proxy server shut down gracefully"),
Ok(Err(e)) => error!("Proxy server error: {}", e),
Expand All @@ -142,7 +142,12 @@ async fn run_with_api(cli: Cli, config: Config) -> Result<(), anyhow::Error> {
let timeout = tokio::time::Duration::from_secs(30);

// Wait for API server
match tokio::time::timeout(timeout, api_handle.take().unwrap()).await {
match tokio::time::timeout(
timeout,
api_handle.take().expect("api_handle consumed once"),
)
.await
{
Ok(Ok(Ok(()))) => info!("API server shut down"),
Ok(Ok(Err(e))) => warn!("API server shutdown error: {}", e),
Ok(Err(e)) => warn!("API server task error: {}", e),
Expand All @@ -155,7 +160,12 @@ async fn run_with_api(cli: Cli, config: Config) -> Result<(), anyhow::Error> {
}

// Wait for proxy server
match tokio::time::timeout(timeout, proxy_handle.take().unwrap()).await {
match tokio::time::timeout(
timeout,
proxy_handle.take().expect("proxy_handle consumed once"),
)
.await
{
Ok(Ok(Ok(()))) => info!("Proxy server shut down"),
Ok(Ok(Err(e))) => warn!("Proxy server shutdown error: {}", e),
Ok(Err(e)) => warn!("Proxy server task error: {}", e),
Expand Down
Loading
Loading