http

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 49 Imported by: 3

Documentation

Overview

Package http adapts Datly runtime execution to HTTP transport.

Index

Constants

View Source
const DefaultCacheInvalidateURI = "/v1/api/cache/invalidate"
View Source
const DefaultCacheWarmURI = "/v1/api/cache/warmup"
View Source
const DefaultDocURI = "/v1/api/meta/doc"
View Source
const DefaultOpenAPIURI = "/v1/api/meta/openapi"

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKey

type APIKey struct {
	URI, Header, Value string
	Secret             *scy.Resource
}

APIKey retains original configuration names and raw URI-prefix matching.

type APIKeys

type APIKeys []APIKey

func (APIKeys) Apply

func (keys APIKeys) Apply(component *spec.Component)

Apply acts only on a stage-owned component clone. Matching configured keys override authored route keys, as original gateway router assembly did.

func (APIKeys) Resolve

func (keys APIKeys) Resolve(ctx context.Context) (APIKeys, error)

Resolve detaches, validates and resolves secrets during generation staging.

type AsyncAdmission

type AsyncAdmission interface {
	Begin(context.Context) (context.Context, AsyncService, func(), error)
}

AsyncAdmission borrows Manager's already-pinned generation for this HTTP request and tracks preparation, execution and response handling until release.

type AsyncInspect

type AsyncInspect struct {
	Result bool
	JobID  string
	Target spec.RouteRef
}

Result requires a real completed reader and current target query/body/JWT sources. False is status-only and never invokes the reader. SyncFlag may be configured on a result route to explicitly refresh instead of cache-only lookup.

type AsyncRoute

type AsyncRoute struct {
	Route    spec.RouteRef
	MatchKey string
	SyncFlag string
	// Inspect configures a separate authored route to inspect exact stored IDs.
	// Its input contract still verifies any declared JWT before status authorization.
	Inspect *AsyncInspect
}

AsyncRoute explicitly enables original default scheduling for an exact public route. Controls name existing canonical input fields, never HTTP parameter locations. No implicit async/sync query flag or arbitrary target is accepted.

type AsyncService

type AsyncService interface {
	Exchange(context.Context, jobs.Submission) (*jobs.Exchange, error)
}

AsyncService is supplied by application.Manager with its generation and owned admission lifetime. It delegates durable work to the existing jobs.Service.

type CacheInvalidationConfig added in v1.1.0

type CacheInvalidationConfig struct {
	Timeout   time.Duration
	Authorize func(context.Context, *stdhttp.Request, dexec.ComponentTarget) error
}

CacheInvalidationConfig enables cache administration independently of warmup. Authorize must grant administrator access to this exact server-selected target.

type Config

type Config struct {
	// Metrics opts into diagnostic response headers. Nil disables them.
	Metrics *MetricsConfig `json:"Metrics,omitempty" yaml:"Metrics,omitempty"`
	Async   []AsyncRoute   `json:"Async,omitempty" yaml:"Async,omitempty"`
	// StaticLocalRoot is an optional caller-owned local filesystem authority.
	// Configured ContentURL paths beneath it must be relative and symlink-free.
	// Keep it open until all reloads finish. JSON configuration cannot grant it.
	StaticLocalRoot   *os.Root `json:"-"`
	StaticContent     []*spec.StaticContent
	ContentURL        string
	APIKeys           APIKeys                  `json:"APIKeys,omitempty" yaml:"APIKeys,omitempty"`
	DisableCors       bool                     `json:"DisableCors,omitempty" yaml:"DisableCors,omitempty"`
	CORS              *spec.CORS               `json:"CORS,omitempty" yaml:"CORS,omitempty"`
	APIPrefix         string                   `json:"APIPrefix,omitempty" yaml:"APIPrefix,omitempty"`
	Meta              Meta                     `json:"Meta,omitempty" yaml:"Meta,omitempty"`
	OpenAPI           *OpenAPIConfig           `json:"OpenAPI,omitempty" yaml:"OpenAPI,omitempty"`
	Warmup            *WarmupConfig            `json:"-" yaml:"-"`
	CacheInvalidation *CacheInvalidationConfig `json:"-" yaml:"-"`
	// Authorize applies application policy to every resolved component target
	// after route/API-key checks and before request binding or execution.
	Authorize func(context.Context, *stdhttp.Request, dexec.ComponentTarget) error `json:"-" yaml:"-"`
}

Config is the application HTTP policy. A nil CORS policy selects safe noncredentialed defaults; an explicit empty CORS policy remains empty.

func (Config) Build

func (c Config) Build(ctx context.Context, input HandlerInput) (*Handler, error)

Build validates policy and freezes configured metadata from the registrations used by Runtime. Call it while staging, before publishing the returned handler.

func (Config) NewHandler

func (c Config) NewHandler(rt *druntime.Runtime, log xlogger.Logger, version string) (*Handler, error)

type DocumentAccess

type DocumentAccess struct {
	APIKeyHeader string `json:"APIKeyHeader" yaml:"APIKeyHeader"`
	APIKeyValue  string `json:"APIKeyValue" yaml:"APIKeyValue"`
}

func (*DocumentAccess) Authorize

func (p *DocumentAccess) Authorize(request *http.Request) error

Authorize applies the same explicit key policy to documents and configured warmup administration. A nil document policy retains public-document behavior.

func (*DocumentAccess) Validate

func (p *DocumentAccess) Validate() error

type DocumentExport

type DocumentExport struct {
	URL    string
	Path   string
	Format string
}

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(rt *druntime.Runtime, log xlogger.Logger, version string) *Handler

func (*Handler) ExportOpenAPI

func (h *Handler) ExportOpenAPI(request openapi.ExportRequest) ([]byte, error)

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(writer stdhttp.ResponseWriter, req *stdhttp.Request)

func (*Handler) Shutdown

func (h *Handler) Shutdown(ctx context.Context) error

Shutdown stops accepting warmups, cancels server operations, and waits for their completion up to ctx's deadline. Call alongside http.Server.Shutdown.

type HandlerInput

type HandlerInput struct {
	Async      AsyncAdmission
	Runtime    *druntime.Runtime
	Components []*registry.RegisteredComponent
	Logger     xlogger.Logger
	Version    string
}

HandlerInput carries canonical registrations only during HTTP staging. They are consumed to freeze documents, never exposed as a mutable registry.

type Meta

type Meta struct {
	// AllowedSubnet retains original RemoteAddr prefix matching (not CIDR parsing).
	AllowedSubnet      []string `json:"AllowedSubnet,omitempty" yaml:"AllowedSubnet,omitempty"`
	OpenApiURI         string   `json:"OpenApiURI,omitempty" yaml:"OpenApiURI,omitempty"`
	DocURI             string   `json:"DocURI,omitempty" yaml:"DocURI,omitempty"`
	CacheWarmURI       string   `json:"CacheWarmURI,omitempty" yaml:"CacheWarmURI,omitempty"`
	CacheInvalidateURI string   `json:"CacheInvalidateURI,omitempty" yaml:"CacheInvalidateURI,omitempty"`
}

Meta preserves original Init semantics: empty selects the default URI; a nonempty whitespace value explicitly disables warmup route activation.

type MetricsConfig

type MetricsConfig struct {
	AllowSQL  bool                      `json:"AllowSQL,omitempty" yaml:"AllowSQL,omitempty"`
	Authorize func(*http.Request) error `json:"-" yaml:"-"`
}

MetricsConfig is operator policy for client-requested diagnostic headers. Configuring it enables SQL-redacted metrics; AllowSQL separately enables SQL and arguments for debug requests. Authorize can further restrict each caller.

type OpenAPIConfig

type OpenAPIConfig struct {
	Info            openapi3.Info   `json:"Info" yaml:"Info"`
	AggregateAccess *DocumentAccess `json:"AggregateAccess,omitempty" yaml:"AggregateAccess,omitempty"`
	RouteAccess     *DocumentAccess `json:"RouteAccess,omitempty" yaml:"RouteAccess,omitempty"`
	// StartupExports is consumed by standalone after initial publication, before
	// listener admission. Rendering remains owned by Manager.ExportOpenAPI.
	StartupExports []DocumentExport `json:"StartupExports,omitempty" yaml:"StartupExports,omitempty"`
}

OpenAPIConfig opts application staging into document generation. Document access is independent of the component security described inside documents. Nil access policies retain original public document-route behavior.

type WarmupConfig

type WarmupConfig struct {
	Lifetime  *WarmupLifetime
	Timeout   time.Duration
	Authorize func(context.Context, *stdhttp.Request, dexec.ComponentTarget) error
	// AdminHeaders are the extra request headers available to Authorize. API-key
	// and canonical JWT headers are copied automatically; bodies are never retained.
	AdminHeaders []string
	// Completed receives preparation failures and every dispatched operation outcome,
	// even after client cancellation. Callbacks must support concurrent requests.
	Completed func(WarmupResult, error)
}

WarmupConfig supplies server lifetime and explicit administration policy. Authorize must authorize this exact target; a successful component JWT alone does not grant cache administration. Lifetime must be server-owned.

type WarmupLifetime

type WarmupLifetime struct {
	// contains filtered or unexported fields
}

WarmupLifetime owns admission and completion across any handlers sharing it. It stores no handlers, generations or requests. Application.Manager supplies one instance to all its staged HTTP generations, including pinned generations.

func NewWarmupLifetime

func NewWarmupLifetime(parent context.Context) *WarmupLifetime

func (*WarmupLifetime) Shutdown

func (l *WarmupLifetime) Shutdown(ctx context.Context) error

Shutdown rejects new accepted operations, cancels authorization, preparation and execution, then joins all previously accepted work. Repeated calls can wait again after an earlier caller deadline. Callbacks must honor operation context.

type WarmupResult

type WarmupResult struct {
	Target string `json:"target"`
	Groups int    `json:"groups"`
	Status string `json:"status"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL