58 lines
1.7 KiB
Go
58 lines
1.7 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/bluesky-social/indigo/atproto/identity"
|
|
)
|
|
|
|
// 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
|
|
directory identity.Directory
|
|
}
|
|
|
|
// NewATProtoHandler creates a new HTTP handler wrapper
|
|
func NewATProtoHandler(handler http.Handler) *ATProtoHandler {
|
|
return &ATProtoHandler{
|
|
handler: handler,
|
|
directory: identity.DefaultDirectory(),
|
|
}
|
|
}
|
|
|
|
// 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/<name>/manifests/<reference>
|
|
// /v2/<name>/blobs/<digest>
|
|
|
|
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
|