{"modulePath":"github.com/openflange/openflange-go","version":"v0.0.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package httpserver\n\nPackage httpserver serves OpenFlange pipes with the HTTP Pipe Protocol (openflange.org/http/v0.1): versioned discovery, execution sessions, one independent streaming request per port, an authoritative session status, expiry and cancellation.\n\n\tsrv := httpserver.New(httpserver.Config{Registry: eng.Registry, Resolver: eng.Resolver, EvalExpr: openflange.EvalExpr})\n\tif _, err := srv.Add(ctx, \"./examples/email/normalize-and-mask-email\"); err != nil { ... }\n\terr := srv.Serve(ctx, listener) // until ctx is done; sessions are cancelled on shutdown\n\nA Server is an http.Handler, so it can also be mounted in an existing HTTP server; call Close when done.\n\nSecurity model. Served pipes run with exactly the grants in Config (Grants / Trusted): a client can choose parameters and ports, never permissions, and never uploads code. Config.Token, when set, is required as a bearer token for discovery and session creation; every session gets its own random, short-lived bearer token that is valid for that session only. Credentials are accepted in the Authorization header only: a request with a query string is rejected. The server speaks plain HTTP; TLS termination is the operator's job, and intermediaries must not buffer requests or responses.\n\n## Constants\n\n```go\nconst (\n\tDefaultIdleTTL         = 60 * time.Second\n\tDefaultRetention       = 60 * time.Second\n\tDefaultMaxSessions     = 64\n\tDefaultMaxRequestBytes = 1 \u003c\u003c 20\n\tDefaultPortBuffer      = 16\n)\n```\nDefaults of Config.\n\n```go\nconst Spec = \"openflange.org/http/v0.1\"\n```\nSpec is the protocol identifier carried in the pipe list.\n\n```go\nconst StatusTrailer = \"OpenFlange-Status\"\n```\nStatusTrailer is the advisory trailer of output responses.\n\n## Functions\n\n```go\nfunc IsLoopbackAddr(addr string) bool\n```\nIsLoopbackAddr reports whether a listen address (\"host:port\") binds only loopback interfaces.\n\n## Types\n\n```go\ntype Access struct {\n\tTime     time.Time     `json:\"time\"`\n\tMethod   string        `json:\"method\"`\n\tPath     string        `json:\"path\"`\n\tStatus   int           `json:\"status\"`\n\tBytes    int64         `json:\"bytes\"`\n\tDuration time.Duration `json:\"-\"`\n\tMillis   int64         `json:\"durationMs\"`\n\tRemote   string        `json:\"remote\"`\n\t// Aborted is set when a streaming response was cut off (failed or\n\t// cancelled session, or the client went away).\n\tAborted bool `json:\"aborted,omitempty\"`\n}\n```\nAccess is one access-log entry.\n\n```go\ntype Config struct {\n\t// Registry provides adapters and builtin pipes. Required.\n\tRegistry *adapter.Registry\n\t// Resolver resolves the references of served pipelines (default: local\n\t// paths, std: and builtin:).\n\tResolver pipeline.Resolver\n\t// EvalExpr evaluates `$expr` parameter bindings of served pipelines.\n\tEvalExpr func(ctx context.Context, expr string, params map[string]any) (any, error)\n\t// Grants are the permissions every served pipe runs with; Trusted grants\n\t// everything the pipes declare (not sandbox-enforced). Clients cannot\n\t// widen them.\n\tGrants  manifest.Permissions\n\tTrusted bool\n\t// Env and Secrets are the providers for `$env` and `$secret` bindings of\n\t// served pipelines (default: the process environment).\n\tEnv     func(string) (string, bool)\n\tSecrets func(string) (string, bool)\n\n\t// Token, when non-empty, must be presented as `Authorization: Bearer` for\n\t// discovery and session creation.\n\tToken string\n\t// BasePath is the URL prefix of the protocol (\"{base}\" without scheme and\n\t// host), e.g. \"/v1\". Default: \"\".\n\tBasePath string\n\t// PublicURL is the externally visible base URL (scheme, host and base\n\t// path), used for the informative `url`/`urls` members when the server\n\t// is behind a proxy. Default: derived from each request.\n\tPublicURL string\n\t// Revision identifies the deployed implementation in definitions.\n\t// Default: a hash of the served pipe's package contents.\n\tRevision string\n\n\t// IdleTTL is how long a session may stay without any attachment before\n\t// it expires, and how long an enabled port may stay unattached once the\n\t// session has started (default 60 s).\n\tIdleTTL time.Duration\n\t// Retention is how long a terminal session stays retrievable (default\n\t// 60 s); afterwards its URLs answer 410.\n\tRetention time.Duration\n\t// MaxDuration bounds the total running time of a session (0 = no limit);\n\t// exceeding it fails the session with E_TIMEOUT.\n\tMaxDuration time.Duration\n\t// MaxSessions bounds concurrently open (non-terminal) sessions (default\n\t// 64); beyond it session creation answers 429.\n\tMaxSessions int\n\t// MaxRequestBytes bounds JSON request bodies (default 1 MiB).\n\tMaxRequestBytes int64\n\t// MaxInputBytes bounds each input stream (0 = no limit); exceeding it\n\t// fails the session with E_RESOURCE.\n\tMaxInputBytes int64\n\t// PortBuffer is the number of batches buffered between an HTTP stream\n\t// and the pipe, per port (default 16). Buffers are bounded: a slow\n\t// reader blocks the pipe, a slow pipe stops the server reading inputs.\n\tPortBuffer int\n\n\t// Log, when set, receives one entry per finished request. Session ids\n\t// are abbreviated and credentials never appear.\n\tLog func(Access)\n}\n```\nConfig configures a Server. The zero value of every optional field selects the documented default.\n\n```go\ntype PipeInfo struct {\n\tID       string `json:\"id\"`\n\tVersion  string `json:\"version\"`\n\tTitle    string `json:\"title,omitempty\"`\n\tRevision string `json:\"revision,omitempty\"`\n\t// Target is what is executed (a path or reference).\n\tTarget  string   `json:\"target\"`\n\tInputs  []string `json:\"inputs\"`\n\tOutputs []string `json:\"outputs\"`\n}\n```\nPipeInfo describes one served pipe.\n\n```go\ntype Server struct {\n\t// contains filtered or unexported fields\n}\n```\nServer is an HTTP Pipe Protocol server. Create it with New.\n\n```go\nfunc New(cfg Config) *Server\n```\nNew creates a Server. Add pipes before serving.\n\n```go\nfunc (s *Server) Add(ctx context.Context, target string) (*PipeInfo, error)\n```\nAdd serves one target: a pipe directory, a manifest file, a standalone pipeline file, or a reference such as \\`std:filter\\`. The target is compiled once with the server's grants so that a pipe that cannot run (missing grant, missing interpreter, invalid pipeline) is refused now rather than in every session.\n\n```go\nfunc (s *Server) AddDir(ctx context.Context, dir string) ([]*PipeInfo, error)\n```\nAddDir serves every pipe discovered in a package directory (see manifest.Discover).\n\n```go\nfunc (s *Server) AddManifest(ctx context.Context, m *manifest.Manifest) (*PipeInfo, error)\n```\nAddManifest serves an in-memory manifest, for example a builtin pipe an application registered with adapter.Registry.RegisterBuiltin.\n\n```go\nfunc (s *Server) Close()\n```\nClose cancels every session, waits for their pipes to stop and releases all timers. New sessions are refused with 503 afterwards. Idempotent.\n\n```go\nfunc (s *Server) Pipes() []PipeInfo\n```\nPipes lists the served pipes, sorted by id.\n\n```go\nfunc (s *Server) Serve(ctx context.Context, l net.Listener) error\n```\nServe accepts connections on l until ctx is done, then cancels all sessions and shuts the listener down. It returns nil after a clean shutdown.\n\n```go\nfunc (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)\n```\nServeHTTP implements http.Handler: the seven routes of http/v0.1 §3.\n\n```go\nfunc (s *Server) Sessions() int\n```\nSessions returns the number of open (non-terminal) sessions.\n\n","path":"github.com/openflange/openflange-go/httpserver","name":"httpserver","synopsis":"Package httpserver serves OpenFlange pipes with the HTTP Pipe Protocol (openflange.org/http/v0.1): versioned discovery, execution sessions, one independent streaming request per port, an authoritative session status, expiry and cancellation.","isRedistributable":true}
