/caddy-bandwidth

Extend your Caddy v2 server with dynamic bandwidth throttling. Ideal for CDN use-cases. 🛠

Primary LanguageGo

🚀 Caddy Bandwidth Limiter Plugin

Rev up your Caddy v2 server with the ability to finely control the bandwidth of your HTTP responses. Perfectly designed for CDN use-cases, this is not just another plugin — it's a key component of our soon-to-launch Media Edge software, meticulously crafted from scratch! 🛠

🔗 Dive into Caddy's magic on their GitHub.

📦 Installation

Plug into the full power of Caddy by integrating our plugin. Let's get started:

  1. Grab xcaddy:
go get -u github.com/caddyserver/xcaddy/cmd/xcaddy
  1. Build Caddy with our bandwidth plugin:
xcaddy build --with github.com/mediafoundation/caddy-bandwidth

🎉 Voilà! You've got a caddy binary, now supercharged with our plugin.

🖋 Usage

Eager to throttle bandwidth? Use the bandwidth directive in your Caddyfile to set the max bytes-per-second:

localhost
route /myroute {
    bandwidth {
        limit 100000
    }
}

💡 Real-World CDN Example

Designed with CDN use-cases in mind, you can add bandwidth limits dynamically based on headers or other conditions:

{
    order bandwidth before header
}

header Server "MediaEdge vX.Y.Z"
reverse_proxy http://localhost:8080 {
    @hasBandwidthLimit header X-Bandwidth-Limit Yes
    handle_response @hasBandwidthLimit {
        bandwidth {
            limit 50000
        }
    }
}
  • order bandwidth before header: Place the bandwidth module before the header module in the processing order.

This allows you to have fine-grained control over bandwidth limits on a per-request basis!

🛠 Development

Our plugin adheres to standard Go conventions, featuring a Middleware struct that uses the caddyhttp.MiddlewareHandler interface. The limitedResponseWriter is meticulously designed to limit bandwidth.

💡 Ideas? Contributions are welcome! Feel free to submit issues and pull requests.

📜 License

Under the MIT License. Use responsibly.

📢 Join Our Community