From 49a87ec97b2ed0acd42bd09dc956048ad7289b72 Mon Sep 17 00:00:00 2001 From: "dzianis.lituyeu" Date: Wed, 1 Apr 2026 13:39:34 +0300 Subject: [PATCH] Rework features --- Cargo.toml | 3 +-- README.md | 63 ++++++++++++++++++++++++----------------------------- src/main.rs | 4 ++-- 3 files changed, 31 insertions(+), 39 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 597b085..76bc547 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -84,8 +84,7 @@ name = "proxy_bench" harness = false [features] -default = ["cli", "tls"] +default = ["cli", "tls", "api"] cli = ["dep:clap", "dep:tracing-subscriber"] tls = ["dep:hyper-tls"] api = ["dep:serde", "dep:serde_json"] -full = ["cli", "tls", "api"] diff --git a/README.md b/README.md index 96e3184..46705f2 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ Add or modify request headers. ```caddy localhost:8080 { - header X-Forwarded-For {remote_host} + header X-Request-ID {uuid} header X-Custom-Header custom-value reverse_proxy backend:3000 } @@ -253,7 +253,7 @@ localhost:8080 { ```caddy localhost:8080 { - header X-Forwarded-For {remote_host} + header X-Forwarded-For {header.X-Forwarded-For} header X-Request-ID {uuid} uri_replace /api /backend reverse_proxy http://backend:3000 @@ -278,63 +278,56 @@ Use placeholders in header values: - `{header.Name}` - Value of request header with that name - `{env.VAR}` - Value of environment variable - `{uuid}` - Random UUID -- `{remote_host}` - Remote host (requires `auth` feature) ## Features ### Default Features -- `cli` - Command-line interface support (enabled by default) -- `tls` - HTTPS backend support (enabled by default) +- `cli` - Command-line interface support +- `tls` - HTTPS backend support +- `api` - Management API for runtime configuration ### Optional Features ```toml +# Minimal - core proxy only (for embedding in other applications) +[dependencies] +tiny-proxy = { version = "0.1", default-features = false } + +# With HTTPS backend support +[dependencies] +tiny-proxy = { version = "0.1", default-features = false, features = ["tls"] } + +# With management API [dependencies] -tiny-proxy = { version = "0.1", features = ["full"] } +tiny-proxy = { version = "0.1", default-features = false, features = ["tls", "api"] } -# Or select specific features -tiny-proxy = { version = "0.1", features = ["cli", "tls", "api"] } +# Full standalone (same as default) +[dependencies] +tiny-proxy = { version = "0.1" } ``` #### `cli` (default) Enable CLI dependencies and `tiny-proxy` binary. -#### `auth` - -Authentication and authorization support: - -```rust -use tiny_proxy::auth; - -// Validate token -let is_valid = auth::validate_token(&req, "http://auth-service/validate").await?; - -// Process header substitutions -let value = auth::process_header_substitution("Bearer {header.Authorization}", &req)?; -``` - #### `tls` (default) Enable HTTPS backend support using `hyper-tls`. -#### `api` +#### `api` (default) Management API for runtime configuration: ```rust use tiny_proxy::api; +use std::sync::Arc; use tokio::sync::RwLock; let config = Arc::new(RwLock::new(Config::from_file("config.caddy")?)); api::start_api_server("127.0.0.1:8081", config).await?; ``` -#### `full` - -Enable all features (`cli`, `auth`, `api`). - ## API Documentation See the [module documentation](https://docs.rs/tiny-proxy) for detailed API reference. @@ -418,17 +411,20 @@ tiny-proxy/ ### Build with Features ```bash -# CLI only (default) +# Default (CLI + TLS + API) cargo build # Library only (no CLI dependencies) cargo build --no-default-features -# Full features -cargo build --features full +# Library with HTTPS support +cargo build --no-default-features --features tls -# Specific features -cargo build --features auth,api +# Library with API for config management +cargo build --no-default-features --features tls,api + +# CLI without API +cargo build --no-default-features --features cli,tls ``` ### Run Examples @@ -439,9 +435,6 @@ cargo run --example basic # Background execution cargo run --example background - -# Hot-reload (with auth feature) -cargo run --example hot_reload --features auth ``` ## Roadmap diff --git a/src/main.rs b/src/main.rs index 59a01a9..bd00396 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,10 +5,10 @@ use tracing_subscriber::EnvFilter; use tiny_proxy::cli::Cli; use tiny_proxy::config::Config; -#[cfg(feature = "cli")] +#[cfg(feature = "api")] use std::sync::Arc; -#[cfg(feature = "cli")] +#[cfg(feature = "api")] use tokio::sync::{broadcast, RwLock}; #[cfg(feature = "api")]