Documentation
¶
Overview ¶
Package server is fenster's OpenAI-compatible HTTP layer. It is pure: it takes a Backend interface and exposes apfel's wire format byte-for-byte.
DRY: all error responses go through writeError; all chat-success responses go through writeChatResponse; all SSE chunks go through writeSSE.
The Mux uses Go 1.22's stdlib pattern routing (METHOD /path) so we don't pull in a third-party router.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultOriginAllowlist ¶
func DefaultOriginAllowlist() []string
DefaultOriginAllowlist returns the origins fenster (and apfel) allow by default: localhost variants only. Apfel matches on the host portion of the Origin header, accepting common loopback names regardless of port or scheme.
func OriginAllowed ¶
OriginAllowed reports whether the given Origin header value is in the allowlist. Empty origin → allowed (curl, SDK use, no CORS context).
"*" in the allowlist matches any origin (footgun mode).
For non-wildcard entries, we compare scheme + host (port-agnostic) so http://localhost:3000 matches an allowlist entry of http://localhost.
Types ¶
type Config ¶
type Config struct {
Backend backend.Backend
EnableCORS bool // when false, OPTIONS still resolves but no ACAO is emitted
BearerToken string // optional; when non-empty, /v1/* requires Authorization: Bearer <token>
AllowedOrigins []string // origin allowlist; nil → DefaultOriginAllowlist
NoOriginCheck bool // disable origin check (preserves bearer auth)
PublicHealth bool // when true, /health is reachable without token
Footgun bool // disables origin + bearer checks; CORS preflight wide-open
BindHost string // bind host; loopback bypasses /health auth automatically
Debug bool
}
Config configures NewMux.
type LogEntry ¶
type LogEntry struct {
Time string `json:"time"`
Method string `json:"method"`
Path string `json:"path"`
Status int `json:"status"`
DurationMs int64 `json:"duration_ms"`
RequestBody string `json:"request_body"`
ResponseBody string `json:"response_body"`
}
LogEntry is one captured request/response pair.
type LogStore ¶
type LogStore struct {
// contains filtered or unexported fields
}
LogStore is a small ring buffer of LogEntry.
func NewLogStore ¶
NewLogStore creates a store with capacity max.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State is the shared, request-spanning state (active request gauge, etc.).
func (*State) ActiveRequests ¶
ActiveRequests returns the current count.
func (*State) IncRequest ¶
func (s *State) IncRequest() func()
IncRequest atomically increments the active-request counter; returns a decrement function for defer.