Skip to main content

Crate tiny_proxy

Crate tiny_proxy 

Source
Expand description

Tiny Proxy Server - Embeddable HTTP Reverse Proxy

This library provides a lightweight, configurable HTTP reverse proxy that can be embedded into Rust applications or run as a standalone CLI tool.

§Features

  • Configuration via Caddy-like syntax
  • Path-based routing with pattern matching
  • Header manipulation
  • URI rewriting
  • HTTP/HTTPS backend support

§Example (Library Mode)

use tiny_proxy::{Config, Proxy};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Load configuration from file
    let config = Config::from_file("config.caddy")?;

    // Create and start proxy
    let proxy = Proxy::new(config);
    proxy.start("127.0.0.1:8080").await?;

    Ok(())
}

§Example (Background Execution)

To run the proxy in the background while doing other work:

use tiny_proxy::{Config, Proxy};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let config = Config::from_file("config.caddy")?;
    let proxy = Proxy::new(config);

    // Spawn proxy in background
    let handle = tokio::spawn(async move {
        if let Err(e) = proxy.start("127.0.0.1:8080").await {
            eprintln!("Proxy error: {}", e);
        }
    });

    // Do other work here...

    handle.await?;
    Ok(())
}

§Example (CLI Mode)

When built as a binary, the proxy can be run from command line:

tiny-proxy --config config.caddy --addr 127.0.0.1:8080

§Configuration Format

The proxy uses a Caddy-like configuration format:

localhost:8080 {
    reverse_proxy backend:3000
    header X-Forwarded-For {remote_ip}
}

For more configuration options, see the config module documentation.

Re-exports§

pub use config::Config;
pub use error::ProxyError;
pub use error::Result;
pub use proxy::ActionResult;
pub use proxy::Proxy;
pub use api::start_api_server;

Modules§

api
Management API module for tiny-proxy
cli
config
error
Error types for tiny-proxy
proxy