tourze / http-forward-bundle
Symfony Bundle for HTTP request forwarding with middleware support
Installs: 14
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/http-forward-bundle
Requires
- doctrine/collections: ^2.3
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^3.0
- doctrine/persistence: ^4.1
- easycorp/easyadmin-bundle: ^4
- knplabs/knp-menu: ^3.7
- monolog/monolog: ^3.1
- psr/log: ^3|^2|^1
- symfony/config: ^7.3
- symfony/console: ^7.3
- symfony/dependency-injection: ^7.3
- symfony/doctrine-bridge: ^7.3
- symfony/event-dispatcher: ^7.3
- symfony/event-dispatcher-contracts: ^3
- symfony/form: ^7.3
- symfony/framework-bundle: ^7.3
- symfony/http-client: ^7.3
- symfony/http-client-contracts: ^3.6
- symfony/http-foundation: ^7.3
- symfony/http-kernel: ^7.3
- symfony/monolog-bridge: ^7.3
- symfony/property-access: ^7.3
- symfony/routing: ^7.3
- symfony/string: ^7.3
- symfony/twig-bundle: ^7.3
- symfony/validator: ^7.3
- symfony/yaml: ^7.3
- tourze/access-key-bundle: 1.0.*
- tourze/bundle-dependency: 1.*
- tourze/doctrine-indexed-bundle: 1.0.*
- tourze/doctrine-timestamp-bundle: 1.0.*
- tourze/easy-admin-enum-field-bundle: 1.0.*
- tourze/easy-admin-menu-bundle: 1.0.*
- tourze/enum-extra: 1.0.*
- tourze/load-balancer: 1.0.*
- tourze/symfony-cron-job-bundle: 1.0.*
- tourze/symfony-dependency-service-loader: 1.0.*
- tourze/symfony-routing-auto-loader-bundle: 1.0.*
Requires (Dev)
- doctrine/data-fixtures: ^2.0
- doctrine/doctrine-fixtures-bundle: ^4.0
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
- tourze/phpunit-base: 1.*
- tourze/phpunit-doctrine-entity: 1.*
- tourze/phpunit-enum: 1.*
- tourze/phpunit-symfony-kernel-test: 1.0.*
- tourze/phpunit-symfony-unit-test: 1.*
- tourze/phpunit-symfony-web-test: 1.*
This package is auto-updated.
Last update: 2025-11-03 16:09:32 UTC
README
Symfony Bundle for HTTP request forwarding with middleware support
An enterprise-grade HTTP request forwarding component with complete forwarding capabilities, middleware system, load balancing, and health checks.
Core Features
- ✅ HTTP Request Forwarding - Support all HTTP methods (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS)
- ✅ Streaming Response - Full support for SSE (Server-Sent Events) and chunked transfer
- ✅ Middleware System - 7 built-in middlewares for request/response transformation
- ✅ Load Balancing - Multiple backend support with automatic healthy node selection
- ✅ Health Checks - Proactive backend health monitoring
- ✅ Retry Mechanism - Automatic retry with exponential backoff
- ✅ Fallback Handling - Return preset responses when backends are unavailable
- ✅ Access Control - API key authentication to protect proxy endpoints
- ✅ Visual Management - EasyAdmin backend with drag-and-drop middleware configuration
- ✅ Complete Logging - Record request/response for troubleshooting
Installation
composer require tourze/http-forward-bundle
Quick Start
1. Basic Configuration
Create forwarding rules via EasyAdmin:
- Visit
/admin - Navigate to HTTP Forward → Forward Rules
- Create a new rule with:
- Path Pattern:
/api/* - Backend URL:
https://api.example.com - Middlewares: Select required middlewares
- Path Pattern:
2. Use Forward Controller
Accessing /forward/api/users will automatically forward to the configured backend.
3. Programmatic Usage
use Tourze\HttpForwardBundle\Service\ForwarderService; use Tourze\HttpForwardBundle\Entity\ForwardRule; class YourController { public function __construct( private readonly ForwarderService $forwarderService, ) {} public function proxy(Request $request, ForwardRule $rule): Response { return $this->forwarderService->forward($request, $rule); } }
Middleware System
Built-in Middlewares
| Middleware | Function | Use Case |
|---|---|---|
access_key_auth |
Access key authentication | Protect proxy endpoints, verify client identity |
auth_header |
Authorization header management | Add/replace Authorization header |
header_transform |
Request header transformation | Add, remove, rename request headers |
query_param |
Query parameter handling | Modify URL query parameters |
xml_to_json |
XML to JSON conversion | Response format transformation |
retry |
Retry mechanism | Automatically retry failed requests |
fallback |
Fallback handling | Return default response when backend unavailable |
Visual Configuration
Configure middlewares via drag-and-drop in EasyAdmin:
- Edit a forwarding rule
- In the Middlewares field:
- Select middleware from dropdown
- Click "Add" button
- Expand configuration form to fill parameters
- Drag to adjust execution order
See: Middleware Configuration Guide
Configuration Examples
Access Key Authentication
{
"type": "access_key_auth",
"config": {
"enabled": true,
"required": true,
"fallback_mode": "strict"
}
}
Authorization Header Management
{
"type": "auth_header",
"config": {
"action": "add",
"scheme": "Bearer",
"token": "your-api-key"
}
}
Header Transformation
{
"type": "header_transform",
"config": {
"add": {
"X-Custom-Header": "value",
"X-Client-Version": "1.0"
},
"remove": ["X-Internal-Header"],
"rename": {
"X-Old-Name": "X-New-Name"
}
}
}
Retry Mechanism
{
"type": "retry",
"config": {
"max_attempts": 3,
"delay_ms": 1000,
"backoff_multiplier": 2.0,
"retry_on_status": [429, 500, 502, 503, 504]
}
}
Feature Details
Load Balancing
Support multiple backend configuration with automatic healthy node selection:
// Add multiple Backends to ForwardRule in EasyAdmin // System will automatically round-robin among healthy backends
Health Checks
Use CLI command to check backend status:
# Check all backends php bin/console http-forward:health-check # Check specific backend php bin/console http-forward:health-check --backend-id=1 # Set timeout (seconds) php bin/console http-forward:health-check --timeout=10 # Dry run without modifying status php bin/console http-forward:health-check --dry-run
Streaming Response
Automatically detect and support SSE streaming:
// Enable stream_enabled in ForwardRule // Or request with Accept: text/event-stream
Request Logging
All forwarding requests are logged in ForwardLog entity:
- Request/response headers
- Response status code
- Execution time
- Error messages
- Backend node
View in EasyAdmin: HTTP Forward → Forward Logs
Configuration Reference
Entity Relationships
ForwardRule (Forwarding Rule)
├── name: Rule name
├── path_pattern: Path matching pattern (e.g., /api/*)
├── priority: Priority (higher number = higher priority)
├── stream_enabled: Enable streaming response
├── middlewares: Middleware configuration (JSON)
└── backends: Associated backend list
Backend (Backend Node)
├── name: Node name
├── url: Backend URL
├── weight: Weight (load balancing)
├── status: Health status
├── health_check_url: Health check URL
└── timeout: Timeout (seconds)
ForwardLog (Forward Log)
├── forward_rule: Applied rule
├── backend: Actual backend used
├── status: Request status
├── request_*: Request information
├── response_*: Response information
└── error_message: Error message
Use Cases
API Gateway
Client → HTTP Forward Bundle → Multiple Backend Services
↓
- Authentication middleware
- Header transformation
- Load balancing
- Health checks
- Request logging
OpenAI Proxy
Works with open-ai-http-proxy-bundle to provide complete OpenAI API proxy functionality.
Microservice Routing
Route requests to different microservices based on path rules, supporting:
- Dynamic routing rules
- Request/response transformation
- Service degradation
- Traffic control
Testing
# Run all tests vendor/bin/phpunit # Run specific tests vendor/bin/phpunit tests/Service/ForwarderServiceTest.php # Code quality check vendor/bin/phpstan analyse
Documentation
License
MIT License - See LICENSE file
Related Projects
Provides core forwarding capabilities as infrastructure component for tourze/open-ai-http-proxy-bundle.
Version: 1.0 Maintainer: Tourze Team