Complete Phase 1 Step 1.6: Extract HTTP handlers and middleware to internal/http/
Extracted HTTP handler implementations and middleware (rate limiting and
security headers) from root package to internal/http/, following the
pattern established in Steps 1.1-1.5.
Changes:
New Files:
- internal/http/handlers.go (144 lines)
* Handlers struct for HTTP handler implementations
* ClientMetadata, Login, Callback handlers
* AuthFlow and SessionStore interfaces for dependency injection
* Logger interface matching other internal packages
- internal/http/middleware.go (373 lines)
* RateLimiter with IP-based rate limiting
* SecurityHeadersMiddleware with environment-aware CSP policies
* Localhost detection and HTTPS detection
* SecurityHeadersOptions for customization
- internal/http/middleware_ratelimit_test.go (moved from ratelimit_test.go)
* Updated package declaration to "http"
* Fixed imports (net/http/httptest)
* Added test logger implementation
* Updated all NewRateLimiter calls with loggerGetter parameter
- internal/http/middleware_security_test.go (moved from securityheaders_test.go)
* Updated package declaration to "http"
* Fixed imports (net/http/httptest)
Modified Files:
- client.go
* Added internalhttp import
* ClientMetadataHandler delegates to internal/http (5โ6 lines)
* LoginHandler delegates to internal/http (32โ12 lines, 63% reduction)
* CallbackHandler delegates to internal/http (56โ17 lines, 70% reduction)
* Added authFlowAdapter and sessionStoreAdapter for type conversion
* Total handler code reduction: 93โ35 lines (62% reduction)
- ratelimit.go (fully rewritten as thin wrapper)
* Wraps internal/http.RateLimiter
* NewRateLimiter adapts logger context
* Middleware, Cleanup, StartCleanup delegate to internal
* Size reduction: 117โ43 lines (63% reduction)
- securityheaders.go (fully rewritten as thin wrapper)
* Re-exports SecurityHeadersOptions type
* SecurityHeadersMiddleware delegates to internal/http
* SecurityHeadersMiddlewareWithOptions delegates to internal/http
* Size reduction: 279โ61 lines (78% reduction)
Implementation Details:
- Maintained 100% backward compatibility - all public APIs unchanged
- Used adapter pattern to convert between public and internal types
- Logger interface matches other internal packages
- All handler logic moved to internal package
- Public API provides thin wrappers with type adaptation
- Test files moved to internal/http and updated for new package structure
Testing:
- All existing tests pass with race detection
- Rate limiter tests updated to work with internal package structure
- Security headers tests work unchanged
- No regressions in handler functionality
- Full test coverage maintained
Progress: Phase 1 now 6/8 steps complete (75%)
- โ
Steps 1.1-1.6 complete
- โณ Steps 1.7-1.8 remaining (validation, testing/documentation)
๐ค Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>