6.0 KiB
6.0 KiB
SmartProxy v19.4.0 - Completed Refactoring
Overview
SmartProxy has been successfully refactored with clearer separation of concerns between HTTP/HTTPS traffic handling and low-level connection routing. Version 19.4.0 introduces global ACME configuration and enhanced route management.
Current Architecture (v19.4.0)
HttpProxy (formerly NetworkProxy)
Purpose: Handle all HTTP/HTTPS traffic with TLS termination
Current Responsibilities:
- TLS termination for HTTPS
- HTTP/1.1 and HTTP/2 protocol handling
- HTTP request/response parsing
- HTTP to HTTPS redirects
- ACME challenge handling
- Static route handlers
- WebSocket protocol upgrades
- Connection pooling for backend servers
- Certificate management integration
SmartProxy
Purpose: Central API for all proxy needs with route-based configuration
Current Responsibilities:
- Port management (listen on multiple ports)
- Route-based connection routing
- TLS passthrough (SNI-based routing)
- NFTables integration
- Certificate management via SmartCertManager
- Raw TCP proxying
- Connection lifecycle management
- Global ACME configuration (v19+)
Completed Implementation
Phase 1: Rename and Reorganize ✅
- NetworkProxy renamed to HttpProxy
- Directory structure reorganized
- All imports and references updated
Phase 2: Certificate Management ✅
- Unified certificate management in SmartCertManager
- Global ACME configuration support (v19+)
- Route-level certificate overrides
- Automatic renewal system
- Renamed
network-proxy.ts
tohttp-proxy.ts
- Updated
NetworkProxy
class toHttpProxy
class - Updated all type definitions and interfaces
- Renamed
- Update exports
- Updated exports in
ts/index.ts
- Fixed imports across the codebase
- Updated exports in
Phase 2: Extract HTTP Logic from SmartProxy ✅
-
Create HTTP handler modules in HttpProxy
- Created handlers directory with:
redirect-handler.ts
- HTTP redirect logicstatic-handler.ts
- Static/ACME route handlingindex.ts
- Module exports
- Created handlers directory with:
-
Move HTTP parsing from RouteConnectionHandler
- Updated
handleRedirectAction
to delegate toRedirectHandler
- Updated
handleStaticAction
to delegate toStaticHandler
- Removed duplicated HTTP parsing logic
- Updated
-
Clean up references and naming
- Updated all NetworkProxy references to HttpProxy
- Renamed config properties:
useNetworkProxy
→useHttpProxy
- Renamed config properties:
networkProxyPort
→httpProxyPort
- Fixed HttpProxyBridge methods and references
Phase 3: Simplify SmartProxy
-
Update RouteConnectionHandler
- Remove embedded HTTP parsing
- Delegate HTTP routes to HttpProxy
- Focus on connection routing only
-
Simplified route handling
// Simplified handleRedirectAction private handleRedirectAction(socket, record, route) { // Delegate to HttpProxy this.httpProxy.handleRedirect(socket, route); } // Simplified handleStaticAction private handleStaticAction(socket, record, route) { // Delegate to HttpProxy this.httpProxy.handleStatic(socket, route); }
-
Update NetworkProxyBridge
- Rename to HttpProxyBridge
- Update integration points
Phase 4: Consolidate HTTP Utilities ✅
-
Move HTTP types to http-proxy
- Created consolidated
http-types.ts
ints/proxies/http-proxy/models/
- Includes HTTP status codes, error classes, and interfaces
- Added helper functions like
getStatusText()
- Created consolidated
-
Clean up ts/http directory
- Kept only router functionality
- Replaced local HTTP types with re-exports from HttpProxy
- Updated imports throughout the codebase to use consolidated types
Phase 5: Update Tests and Documentation ✅
-
Update test files
- Renamed NetworkProxy references to HttpProxy
- Renamed test files to match new naming
- Updated imports and references throughout tests
- Fixed certificate manager method names
-
Update documentation
- Updated README to reflect HttpProxy naming
- Updated architecture descriptions
- Updated usage examples
- Fixed all API documentation references
Migration Steps
- Create feature branch:
refactor/http-proxy-consolidation
- Phase 1: Rename NetworkProxy (1 day)
- Phase 2: Extract HTTP logic (2 days)
- Phase 3: Simplify SmartProxy (1 day)
- Phase 4: Consolidate utilities (1 day)
- Phase 5: Update tests/docs (1 day)
- Integration testing (1 day)
- Code review and merge
Benefits
- Clear Separation: HTTP/HTTPS handling is clearly separated from TCP routing
- Better Naming: HttpProxy clearly indicates its purpose
- No Duplication: HTTP parsing logic exists in one place
- Maintainability: Easier to modify HTTP handling without affecting routing
- Testability: Each component has a single responsibility
- Performance: Optimized paths for different traffic types
Future Enhancements
After this refactoring, we can more easily add:
- HTTP/3 (QUIC) support in HttpProxy
- Advanced HTTP features (compression, caching)
- HTTP middleware system
- Protocol-specific optimizations
- Better HTTP/2 multiplexing
Breaking Changes from v18 to v19
NetworkProxy
class renamed toHttpProxy
- Import paths change from
network-proxy
tohttp-proxy
- Global ACME configuration now available at the top level
- Certificate management unified under SmartCertManager
Future Enhancements
- HTTP/3 (QUIC) support in HttpProxy
- Advanced HTTP features (compression, caching)
- HTTP middleware system
- Protocol-specific optimizations
- Better HTTP/2 multiplexing
- Enhanced monitoring and metrics
Key Features in v19.4.0
- Global ACME Configuration: Default settings for all routes with
certificate: 'auto'
- Enhanced Route Management: Better separation between routing and certificate management
- Improved Test Coverage: Fixed test exports and port bindings
- Better Error Messages: Clear guidance for ACME configuration issues
- Non-Privileged Port Support: Examples for development environments