- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1
feat: implement unified HTTP architecture with multi-protocol support and HttpX connector #419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| Very good work @bearice I don't know if you're too busy lately, but could you please implement BIND support in SOCKS5 listener? | 
- Add generic connection pool with trait-based design for protocol-agnostic pooling - Create protocols/http module with HTTP stream abstractions and protocol handler traits - Implement UDP channel lifecycle management with proper session ID generation - Add ALPN-based protocol selection for HTTP/1.1, HTTP/2, and HTTP/3 negotiation - Reorganize code structure: move HTTP-specific code from common/ to protocols/ - Add type aliases to reduce trait object complexity - Fix safety issues: input validation, underflow protection, anyhow error integration - Optimize connection pool with read-then-write lock pattern for better concurrency This establishes the foundation for unified HTTP listener/connector supporting all HTTP versions with proper connection pooling and protocol negotiation. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> refactor: modernize TLS infrastructure and migrate to aws-lc-rs - Migrate from ring to aws-lc-rs crypto provider for better performance - Remove unsupported TLS configuration options (session_tickets, early_data, etc.) - Implement SNI certificate loading with ResolvesServerCertUsingSni - Remove empty configuration structs (TlsCryptoConfig, TlsAlpnConfig) - Consolidate TLS handshake methods: tls_handshake_server() returns (stream, alpn_protocol) tuple - Update socket operations to extract ALPN protocol from TLS streams - Update listeners to handle new TLS handshake signature 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> refactor: rename HTTP types for clarity and prepare for unified architecture - Rename HttpRequest/HttpResponse to HttpRequestV1/HttpResponseV1 for clarity - Update all HTTP proxy code to use new type names throughout codebase - Update context to use set_http_request_v1() method - Prepare foundation for unified HTTP protocol architecture - Maintain backward compatibility for existing HTTP/1.1 functionality This change disambiguates the existing HTTP/1.1 specific types from the upcoming unified HTTP protocol types that will support HTTP/1.1, HTTP/2, and HTTP/3. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> feat: implement HTTP/1.1 protocol handler with unified httpx listener This commit implements Phase 2 of the unified HTTP architecture: - **HTTP/1.1 Protocol Handler**: Complete implementation with request/response parsing, CONNECT tunneling, and WebSocket upgrade support - **Unified httpx Listener**: Multi-protocol listener with ALPN negotiation supporting HTTP/1.1, HTTP/2, HTTP/3 (foundation) - **Stream Architecture**: Refactored socket operations to use IOStream trait for better abstraction - **Comprehensive Testing**: Full test suite including performance, security, and integration tests - **Loop Detection**: Configurable loop detection with hop limits for proxy chains Key Features: - HTTP CONNECT method tunneling for HTTPS traffic - WebSocket protocol upgrade handling - Request/response streaming with proper Content-Length and chunked encoding - TLS termination with ALPN protocol negotiation - Authentication integration with existing auth framework - Comprehensive error handling and logging All tests pass including httpx listener tests, HTTP/1.1 protocol tests, and integration tests. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> refactor: implement unified I/O architecture and HTTP/1.1 improvements - Refactor Context API to use Option<IOBufStream> instead of Result for cleaner error handling - Add comprehensive I/O module with bidirectional copying, buffered streams, and splice optimization - Implement unified HTTP/1.1 protocol handler consolidating parser and stream functionality - Improve copy_bidi with modular design supporting both stream and frame-based protocols - Add configurable I/O loop functions to Context for protocol-specific handling - Enhanced ContextStatistics with sent_bytes/sent_frames tracking methods 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> refactor: migrate comprehensive testing to pytest infrastructure - Replace custom test framework with pytest-native approach using fixtures and conftest.py - Restructure test files into organized test suites: httpx/, matrix/, performance/, security/ - Add pytest plugins for HTML reporting, JSON output, and parameterized test execution - Improve Docker configuration for better debugging (debug builds, additional tools) - Migrate from individual Python test scripts to structured pytest test modules - Remove deprecated test framework files and consolidate shared utilities This modernizes the testing infrastructure while maintaining all existing test coverage and improves maintainability through standard pytest patterns. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> refactor: remove empty Http1Handler struct and move protocol functions to handler - Convert Http1Handler from empty struct to standalone functions, eliminating unnecessary allocations - Move HTTP protocol utility functions from io.rs to handler.rs for better separation of concerns: - expects_100_continue() - should_keep_alive() - prepare_client_response() - prepare_server_request() - Update all call sites to use standalone functions instead of struct methods - Move corresponding tests from io_test.rs to handler.rs test module - Update module exports and imports throughout codebase 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> refactor: remove unused HTTP/2 and HTTP/3 handler stubs - Remove unimplemented Http2Handler and Http3Handler placeholder structs - Clean up exports from http/mod.rs that referenced removed handlers - Clear HTTP/2 and HTTP/3 mod.rs files as they contained only stub implementations These handlers were empty implementations with only bail!() macros and were never actually used in the codebase. They can be re-added when actual HTTP/2 and HTTP/3 support is implemented. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> style: fix code formatting and whitespace in I/O modules - Remove extra blank lines in bidirectional.rs splice loop - Fix comment spacing in copy.rs test mock - Add proper spacing in http_forward_tests.rs loop formatting - Minor whitespace cleanup for consistency 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> refactor: improve HTTP/1.1 error handling and code organization Major improvements to HTTP/1.1 implementation following code review: **Error Handling Improvements:** - Fix accept() error handling in httpx listener - move retry logic to SocketOps layer - Add proper error responses to clients when server response reading fails (HTTP 502) - Fix stream ownership bug in http_io_loop error handling - Classify accept() errors properly: transient vs fatal **Code Organization:** - Extract handle_100_continue_cycle() function to eliminate 4-level nesting - Use consistent StreamPair type throughout HTTP/1.1 implementation - Clean up imports following project conventions (all imports at file header) - Add #[allow(unused_assignments)] to suppress false positive warnings **Architecture:** - Move socket-level retry logic from application layer to SocketOps layer - Simplify listener implementations - only handle truly fatal errors - Improve separation of concerns between socket ops and HTTP protocol logic **Reliability:** - Ensure clients always receive proper HTTP error responses instead of dropped connections - Handle 100 Continue protocol flow more robustly with better error recovery - Make accept() loops resilient to transient network errors 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
| Engineering Review: HTTP/2 Feature ImplementationThis PR introduces significant architectural changes including connection pooling and HTTP protocol restructuring. While the functionality appears comprehensive, there are fundamental engineering issues that need to be addressed before this can be considered production-ready. Critical Issues (Fix Now)1. Connection Pool: Severe Race Conditions and Lock ContentionProblem: The connection pool implementation in  // First check with read lock
{
    let pools = self.pools.read().await;
    if !pools.contains_key(key) {
        return None;
    }
}
// Then acquire write lock - KEY COULD BE REMOVED HERE!
let mut pools = self.pools.write().await;
let connections = pools.get_mut(key)?; // This can panicImpact: This creates a race where another thread can remove the key between the read and write lock acquisition, causing panics or incorrect behavior under load. Additionally, every pool access requires an async lock, creating massive contention. Solution: Use a single atomic operation with proper error handling: let mut pools = self.pools.write().await;
let Some(connections) = pools.get_mut(key) else { return None };Todo: 
 2. Overengineered Abstraction LayersProblem: The PR introduces 6+ levels of abstraction for simple HTTP request/response handling. The  Impact: Performance degradation, increased memory usage, and code that's impossible to reason about. Every HTTP request now goes through multiple wrapper layers. Solution: Keep data structures flat and direct. HTTP is fundamentally simple - don't overcomplicate it. Todo: 
 3. Breaking API Changes Without Migration PathProblem: The PR changes core Context API ( // OLD API - REMOVED
pub fn set_http_request(&mut self, request: HttpRequest)
// NEW API
pub fn set_http_request_v1(&mut self, request: HttpRequestV1)Impact: Breaks existing code, forces all users to rewrite integration code. Solution: Maintain backward compatibility with deprecated warnings, then remove in next major version. Todo: 
 Important Issues (Next)4. Complex I/O Error HandlingProblem: HTTP I/O loop in  Solution: Extract error handling into smaller, composable functions. Each error case should be handled at the appropriate level. Todo: 
 5. Resource Leaks in Connection PoolProblem: The cleanup task  Solution: Implement proper shutdown semantics and connection draining. Todo: 
 Nice to Have (Later)6. Inconsistent Error ResponsesProblem: HTTP error responses are inconsistent between different code paths. Todo: 
 Improvement RoadmapCritical (Fix Now)
 Important (Next)
 Nice to Have (Later)
 SummaryWhile this PR adds useful functionality, it violates several fundamental engineering principles. The connection pool has serious concurrency bugs, the HTTP abstraction layers are overengineered, and breaking changes lack migration paths. Fix the critical race conditions and API breaks before considering merge. The current implementation will cause production issues under load. 🤖 Generated with Claude Code | 
…de support
This commit introduces a modern httpx connector that unifies HTTP proxy functionality
with configurable WebSocket upgrade handling and comprehensive protocol support.
## Key Features
### HttpX Connector Implementation
- Modern HTTP/1.1 proxy connector with connection pooling
- Configurable forward proxy mode (GET/POST/PUT/DELETE support)
- Advanced timeout controls (connect, resolve)
- Protocol negotiation and keep-alive management
### WebSocket Upgrade Handling
- NEW: `intercept_websocket_upgrades` configuration flag
- Automatically routes WebSocket upgrades through CONNECT tunneling
- Prevents HTTP proxies from stripping hop-by-hop headers
- Configurable behavior for compatibility with different upstream proxies
### Test Suite Reorganization
- Restructured httpx tests into 3-tier architecture for component isolation:
  * Tier 1: HttpX Listener + Direct Connector (listener validation)
  * Tier 2: HttpX Listener + HttpX Connector (full pipeline testing)
  * Tier 3: Reverse Listener + HttpX Connector (connector validation)
- Consolidated 12 separate test files into 3 organized test classes
- All 49 tests passing with comprehensive coverage
### Documentation Updates
- Complete CONFIG_GUIDE.md documentation for httpx listener (Section 4.7)
- Complete CONFIG_GUIDE.md documentation for httpx connector (Section 5.7)
- Multi-protocol support documentation (HTTP/1.1, HTTP/2, HTTP/3)
- ALPN negotiation and configuration requirements
- WebSocket upgrade configuration examples
## Technical Implementation
### Connection Architecture
- Unified I/O architecture with bidirectional copying
- Connection pooling with configurable idle timeout
- Protocol-specific configuration embedding
- Advanced error handling and resource cleanup
### HTTP Context Integration
- Enhanced HTTP context for request/response tracking
- WebSocket upgrade detection using existing helper methods
- CONNECT tunneling decision logic
- Memory-efficient request processing
### Configuration Schema
```yaml
connectors:
  - name: httpx
    type: httpx
    server: "http-proxy"
    port: 3128
    enable_forward_proxy: true
    intercept_websocket_upgrades: true  # NEW
    protocol:
      type: "http/1.1"
      keep_alive: true
    pool:
      enable: true
      max_connections: 50
      idle_timeout_secs: 30
```
## Files Modified
- src/connectors/httpx.rs (NEW) - Main httpx connector implementation
- src/protocols/http/http_context.rs (NEW) - HTTP context integration
- CONFIG_GUIDE.md - Comprehensive httpx documentation
- tests/comprehensive/config/httpx.yaml - 3-tier test configuration
- tests/comprehensive/scripts/tests/httpx/ - Reorganized test suite
## Compatibility
- Backward compatible with existing HTTP connectors
- WebSocket upgrade interception disabled by default
- Configurable behavior for different proxy environments
- Full HTTP/1.1 compliance with modern extensions
This implementation provides the foundation for Phase 2 HTTP/2 and HTTP/3 support
while delivering immediate value for HTTP/1.1 proxy scenarios with WebSocket support.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
    Add bi-directional HTTP proxy authentication capabilities with Basic auth support for both client authentication (listener-side) and upstream proxy authentication (connector-side), enabling secure proxy chaining scenarios. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
| PR #419 Review: Unified HTTP ArchitectureExecutive SummaryThis PR attempts to implement a "unified" HTTP architecture but fundamentally misunderstands what good engineering looks like. It's a textbook example of overengineering simple problems while introducing unnecessary complexity that will plague this codebase for years. The core issue: You're solving problems that don't exist with abstractions that nobody asked for. Critical Issues (STOP SHIP)1. Overengineered HttpContext MonstrosityProblem Statement: The  pub struct HttpContext {
    pub request: Option<Arc<HttpRequest>>,
    pub response: Option<Arc<HttpResponse>>,
    pub protocol: Option<String>,
    pub keep_alive: bool,
    pub forward_proxy: bool,
    pub proxy_auth: Option<ProxyAuth>,
    pub alpn: Option<String>,
    pub pool_key: Option<String>,
    pub max_requests: Option<u32>,
    pub h2_max_concurrent_streams: Option<u32>,  // Dead weight for HTTP/1.1
    pub h3_max_bi_streams: Option<u32>,           // Dead weight for HTTP/1.1 and HTTP/2
}Impact Analysis: 
 Concrete Solution: Use protocol-specific contexts with a common trait. Stop trying to be clever: trait HttpContext {
    fn request(&self) -> &HttpRequest;
    fn keep_alive(&self) -> bool;
}
struct Http1Context { /* HTTP/1.1 specific fields */ }
struct Http2Context { /* HTTP/2 specific fields */ }2. Connection Pool Over-AbstractionProblem Statement: The generic connection pool (src/common/connection_pool.rs) uses 3 levels of Arc/RwLock nesting and type aliases to hide the complexity. This is exactly what Linus means by "bad programmers worry about code." type ConnectionPools<M> = Arc<
    RwLock<
        HashMap<
            <M as ConnectionManager>::Key,
            Vec<PooledConnection<<M as ConnectionManager>::Connection>>,
        >,
    >,
>;Impact Analysis: 
 Concrete Solution: A simple pool per protocol. No generics. No magic: struct Http1Pool {
    connections: HashMap<String, Vec<Http1Connection>>,
}3. Callback Hell in HTTP/1.1 HandlerProblem Statement: The  Impact Analysis: 
 Concrete Solution: Return an enum from the handler: enum ConnectionDisposition {
    KeepAlive(IOBufStream),
    Close,
}4. HttpContextExt Trait AbuseProblem Statement: The trait (src/protocols/http/context_ext.rs) adds 238 lines to provide getters/setters that just forward to  Impact Analysis: 
 Concrete Solution: Delete the trait. Access fields directly. Major Issues (Fix Before Merge)5. Inefficient String AllocationsThe protocol field stores  pub protocol: Option<String>,  // BADShould be: pub protocol: Protocol,  // enum Protocol { Http11, H2, H3 }6. No Zero-Copy for HTTP HeadersHeaders are cloned into  7. Missing Error RecoveryThe HTTP/1.1 handler immediately closes connections on any parse error instead of draining the request and sending a proper error response. Performance Implications
 Breaking ChangesWhile the PR claims backward compatibility, the fundamental context restructuring breaks any code that: 
 Security Issues
 Code Smell Summary
 Improvement RoadmapCritical (Fix Now)
 Important (Next)
 Nice to Have (Later)
 The Right ApproachGood code is simple code. The entire HTTP/1.1 implementation should be: 
 No callbacks. No traits. No generic pools. No Arc unless actually needed for sharing. This PR needs fundamental rethinking, not tweaking. | 
Unified HTTP Architecture Implementation
This PR implements a comprehensive unified HTTP architecture that establishes the foundation for supporting HTTP/1.1, HTTP/2, and HTTP/3 protocols through a single, cohesive system.
🎯 Major Features
Unified HttpX Listener & Connector
HTTP Context Architecture
HTTP Common Infrastructure
Connection Management
🔧 Technical Implementation
Core Components
Key Architectural Improvements
HTTP/1.1 Implementation Status
✅ Complete HTTP/1.1 Support:
Multi-Protocol Foundation
🚧 HTTP/2 & HTTP/3 Ready:
📊 Testing & Validation
Comprehensive Test Suite
Test Configuration
tests/comprehensive/config/httpx.yaml: HttpX-specific test configuration🔄 Migration & Compatibility
Backward Compatibility
Configuration Evolution
🚀 Future Work
This PR establishes the foundation for:
📈 Performance Benefits
Testing Status: ✅ All tests pass
Documentation: ✅ Comprehensive inline documentation
Compatibility: ✅ Backward compatible with existing configurations
🤖 Generated with Claude Code
Co-Authored-By: Claude [email protected]