HTTPCan
A simple, high‑performance HTTP request & response service built with Rust and Actix Web. Fully compatible with httpbin.org, with modern streaming and AI‑friendly enhancements.
Quick Links: Quick Start · Installation · Configuration · Examples · OpenAPI & Web UI · API Reference · Production · Library · Development · License
✨ Features
- HTTPBin compatible: Use as a drop‑in replacement for testing/migration
- Modern streaming: Native SSE and NDJSON, AI‑compatible formats (OpenAI/Ollama)
- Tiny Docker image: <10MB, fast to pull and start
- Minimal memory footprint: Efficient async Rust I/O
- High throughput: Actix Web + Tokio
- Observability built‑in: Every response carries
Server-TimingandX-Httpcan-Versionheaders;/healthzliveness probe and/tagsinstance identification
Quick Start
Choose one way to run:
# Docker (recommended)
# Cargo
Installation
🐳 Docker
# Latest image
# Custom port
# Header filtering
📦 Cargo
# Install globally
# Run
🛠️ From Source
# Default (8080)
# Custom port
# Release build
🧰 Configuration
CLI flags:
| Option | Description | Default | Example |
|---|---|---|---|
-p, --port <PORT> |
Port number to listen on | 8080 |
--port 3000 |
--no-current-server |
Do not add current server to OpenAPI servers list |
false |
--no-current-server |
--exclude-headers <HEADERS> |
Exclude headers in responses; comma‑separated; supports wildcard suffix (e.g. x-bar-*) |
"" |
--exclude-headers "x-forwarded-*,cf-*,server" |
--max-bytes <BYTES> |
Max bytes for /bytes & /stream-bytes; over‑limit returns 404 instead of truncating (httpbin #594) |
102400 |
--max-bytes 1048576 |
-h, --help |
Print help information | --help |
|
-V, --version |
Print version | --version |
Notes:
- Built‑in filtering includes reverse proxy/CDN providers (Nginx, Cloudflare, AWS, GCP, Azure).
- When using Docker, ensure
-p host:containermapping matches your--portif you override it.
Usage Examples
# Basic GET
# POST with JSON
Auth
# Basic auth
# Username only (empty password) — enhanced
Status & Redirects
# Specific status
# Random from list
# Inject response headers (rate-limit / Retry-After testing)
# Redirect to a URL (supports form/json)
🔒 Open‑redirect protection on
/redirect‑toUnlike a naive 302,
/redirect-todetects browser clients (viaAccept: text/html) and returns an interstitial warning page instead of silently redirecting. This prevents phishing abuse where attackers exploit your trusted domain (e.g.…/redirect-to?url=https://evil.com).
- Programmatic clients (curl, httpx, …) still receive the standard
302— no API breakage.- Browser clients get a
200HTML page showing the destination URL and requiring an explicit click.- Non‑
http(s)URL schemes (javascript:,data:, …) render as a disabled link.- Destination URLs are HTML‑escaped in the interstitial to prevent XSS.
- The page carries
X-Robots-Tag: noindexto avoid search‑engine indexing.
Compression & Formats
Streaming (SSE/NDJSON)
# SSE
&format=simple
&delay=2000
# NDJSON
&format=simple
&model=llama3&delay=1500
Cookies & Inspection
OpenAPI & Web UI
- OpenAPI spec:
GET /openapi.json - Web UI / API info: visit
/in a browser; renders HTML or JSON based onAcceptheader
API Reference
HTTPBin Compatibility (Overview)
- Methods:
GET /get,POST /post,PUT /put,PATCH /patch,DELETE /delete - Anything:
/anything,/anything/{anything}(supports multiple methods) - Auth: Basic, Hidden Basic, Digest
- Formats: JSON, XML, HTML,
robots.txt,encoding/utf8, gzip/deflate/brotli/zstd - Dynamic:
uuid,bytes,stream,range,links,delay,drip - Redirects:
redirect,relative-redirect,absolute-redirect,redirect-to - Inspection:
headers,ip,user-agent - Response:
cache,etag,response-headers - Cookies:
cookiesCRUD - Images:
image,image/png,image/jpeg,image/webp,image/svg - Status:
/status/{codes}(single or comma‑separated)
For the full, up‑to‑date list and schemas, consult the OpenAPI spec.
HTTPCan Enhancements
- Echo endpoint:
/echoreflects request body and headers (multi‑method) - Methods+:
QUERYHTTP method (RFC 9430 — a safe, idempotent GET with a body) accepted on/anything,/anything/{anything}, and/echo - Auth+: Basic auth with username only; JWT Bearer decode/inspect at
/jwt-bearer - Status+: Content‑type priority:
Accept> requestContent-Type> default; supports custom bodies via query/body - Redirects+:
POST /redirect-tosupportsapplication/x-www-form-urlencoded,multipart/form-data,application/json; browser clients get an open-redirect interstitial (see above) - Streaming+: SSE/NDJSON endpoints with
count,delay, and AI formats (OpenAI/Ollama) - File uploads+: Multiple files with the same field return as array across multipart endpoints
- Observability+:
/healthzliveness probe;/tagsexposesHTTPCAN_*env vars; every response carriesServer-TimingandX-Httpcan-Versionheaders - Method echo+:
/methodechoes any HTTP method name;/head(HEAD‑only) mirrors request headers asX-Echo-* - Status headers+:
?header=Name:Valueinjects response headers on/status/{codes}(repeatable; e.g.Retry-Afterfor rate‑limit testing) - Body encoding+: POST to
/gzip,/deflate,/brotli,/zstd, or/base64returns the request body in the matching encoding
🚀 Production Considerations
Before deploying HTTPCan on the public internet, review these hardening options:
- Open‑redirect protection on
/redirect‑to: Browser clients (detected viaAccept: text/html) receive an interstitial warning page showing the destination URL instead of a silent302. This blocks phishing abuse via…/redirect-to?url=https://evil.comon your trusted domain. Programmatic clients (curl, httpx, …) still get the standard302for API compatibility. Non‑http(s)URL schemes render as a disabled link. - No reflected XSS on
/base64: Decoded content is always returned astext/plain; charset=utf-8, nevertext/html. Browsers display the raw text without rendering embedded<script>tags. - Response header filtering:
- Built‑in (always on): ~100 reverse‑proxy/CDN headers are stripped from all echoed responses by default — Nginx (
x-real-ip,x-forwarded-*), Cloudflare (cf-*), AWS CloudFront/ALB (cloudfront-*,x-amzn-*), GCP (x-appengine-*,x-cloud-trace-context), Azure (x-azure-*,x-ms-*). Prevents infrastructure information leakage without any configuration. - Custom (
--exclude-headers): Add your own patterns to strip additional sensitive headers, with wildcard suffix support:--exclude-headers "x-internal-*,server,x-secret-token".
- Built‑in (always on): ~100 reverse‑proxy/CDN headers are stripped from all echoed responses by default — Nginx (
- Resource limits:
--max-bytescaps/bytesand/stream-bytesresponses (default 100KB); over‑limit requests return404instead of silently truncating (httpbin #594). - Non‑root Docker: The official image runs as a dedicated unprivileged user (
uid 10001).
🦀 Library Usage
Add dependency:
[]
= "0.6"
Embed server:
use HttpCanServer;
async
More examples and advanced config: see LIBRARY_USAGE.md.
Development
# Run checks
# Run locally
Contributions are welcome! Please open issues/PRs for discussion.
License
MIT — see LICENSE.