camel-component-http
HTTP client and server component for rust-camel
Overview
The HTTP component provides HTTP client (producer) and HTTP server (consumer) capabilities for rust-camel. Built on reqwest for clients and axum for servers, it enables REST API integration, webhook handling, and HTTP-based messaging.
Features
- HTTP Server (Consumer): Listen for incoming HTTP requests
- HTTP Client (Producer): Make outgoing HTTP requests
- HTTPS Support: Secure connections with
httpsscheme - Configurable Timeouts: Connect and response timeouts
- SSRF Protection: Optional private IP blocking
- Streaming: Direct stream-to-HTTP piping without materialization
- Header Mapping: Automatic header forwarding
- Status Code Handling: Configurable success ranges
Installation
Add to your Cargo.toml:
[]
= "0.2"
URI Format
http://host:port/path[?options]
https://host:port/path[?options]
Consumer Options (Server)
| Option | Default | Description |
|---|---|---|
| Host/path from URI | - | e.g., http://0.0.0.0:8080/api |
Producer Options (Client)
| Option | Default | Description |
|---|---|---|
httpMethod |
Auto | HTTP method (GET, POST, etc.) |
throwExceptionOnFailure |
true |
Throw on non-2xx responses |
okStatusCodeRange |
200-299 |
Success status code range |
followRedirects |
false |
Follow HTTP redirects |
connectTimeout |
30000 |
Connection timeout (ms) |
responseTimeout |
- | Response timeout (ms) |
allowPrivateIps |
false |
Allow requests to private IPs |
blockedHosts |
- | Comma-separated blocked hosts |
Usage
HTTP Server (Consumer)
use RouteBuilder;
use HttpComponent;
use CamelContext;
let mut ctx = new;
ctx.register_component;
// Simple API endpoint
let route = from
.process
.build?;
HTTP Client (Producer)
// GET request
let route = from
.to
.log
.build?;
// POST request (body becomes request body)
let route = from
.to
.build?;
Dynamic HTTP Method
// Method from header
let route = from
.set_header
.to
.build?;
Dynamic URL
// URL from header
let route = from
.set_header
.to // Base URL, overridden by header
.build?;
HTTPS
let route = from
.to
.build?;
Exchange Headers
Request Headers (Consumer)
| Header | Description |
|---|---|
CamelHttpMethod |
HTTP method (GET, POST, etc.) |
CamelHttpPath |
Request path |
CamelHttpQuery |
Query string |
| All HTTP headers | Forwarded from request |
Response Headers (Producer)
| Header | Description |
|---|---|
CamelHttpResponseCode |
HTTP status code |
CamelHttpResponseText |
Status text |
| All response headers | Forwarded from response |
Request Control Headers (Producer)
| Header | Description |
|---|---|
CamelHttpUri |
Override target URL |
CamelHttpPath |
Append to base URL path |
CamelHttpQuery |
Append query string |
CamelHttpMethod |
Override HTTP method |
Example: REST API Server
use RouteBuilder;
use ;
use CamelContext;
use Body;
async
Example: HTTP Client with Error Handling
let route = from
.to
.build?;
// With custom error handling
let route = from
.error_handler
.to
.process
.build?;
SSRF Protection
By default, the HTTP client blocks requests to private IP addresses for security. To allow:
.to
To block specific hosts:
.to
Streaming & Memory Management
The HTTP producer supports streaming request bodies directly without materializing them in memory. Stream bodies are piped to reqwest using wrap_stream().
Memory limits apply when materialization is required (default: 10MB).
Documentation
License
Apache-2.0
Contributing
Contributions are welcome! Please see the main repository for details.