package server import ( "net/http" "strings" "atcr.io/pkg/atproto" ) // ATProtoHandler wraps an HTTP handler to provide name resolution // This is an optional layer if middleware doesn't provide enough control type ATProtoHandler struct { handler http.Handler resolver *atproto.Resolver } // NewATProtoHandler creates a new HTTP handler wrapper func NewATProtoHandler(handler http.Handler) *ATProtoHandler { return &ATProtoHandler{ handler: handler, resolver: atproto.NewResolver(), } } // ServeHTTP handles HTTP requests with name resolution func (h *ATProtoHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Parse the request path to extract user/image // OCI Distribution API paths look like: // /v2//manifests/ // /v2//blobs/ path := r.URL.Path // Check if this is a v2 API request if strings.HasPrefix(path, "/v2/") { // Extract the repository name parts := strings.Split(strings.TrimPrefix(path, "/v2/"), "/") if len(parts) >= 2 { // parts[0] might be username/DID // We could do early resolution here if needed // For now, we'll let the middleware handle it } } // Delegate to the underlying handler // The registry middleware will handle the actual resolution h.handler.ServeHTTP(w, r) } // Note: In the current architecture, most of the name resolution // is handled by the registry middleware. This HTTP handler wrapper // is here for cases where you need to intercept requests before // they reach the distribution handlers, such as for: // - Custom authentication based on DIDs // - Request rewriting // - Early validation // - Custom API endpoints beyond OCI spec