Files
summercms/modules/pier/host.go
Jakub Zych 24cf6cd931 fix(pier): end only the revoked token's or client's MCP sessions and log the client address (B-WR-04, B-IN-04)
- pact.MCPSubjectChanged and pier.Event gain TokenID and ClientID; a
  narrowed revoked event closes only matching sessions and stateless servers
- cabana fires the admin token revoke with the token row id
- towel.WithClientIP/ClientIP; pier puts the address (surf applies
  http.trusted_proxies) on the resolve context and ResolveBackendToken logs it
2026-10-23 16:21:37 +02:00

42 lines
1.6 KiB
Go

package pier
import "net/http"
// Host is what pier needs from the HTTP router that mounts it, so that pier
// never imports surf (surf imports pier in a binary built with the
// summercms_mcp tag and passes an adapter). Routes lists every registered
// route, Handler returns the compiled middleware chain of one route for an
// in-process dispatch (resolved lazily, after the router has compiled),
// MountStream registers one unbuffered route under the pier pseudo-plugin,
// MountJSON registers one plain GET route for a static JSON document and
// Owner reports the plugin that registered a route, for collision checks.
type Host interface {
Routes() []RouteInfo
Handler(method, pattern string) (http.Handler, bool)
MountStream(method, path string, h http.Handler, middleware ...string) error
MountJSON(method, path string, h http.Handler) error
Owner(method, path string) (string, bool)
}
// clientIPHost is optional for a Host: a host that knows the application's
// trusted proxies answers the client address of a request, which pier puts
// on the token resolvers' context (towel.WithClientIP). Without it pier uses
// the host part of the request's RemoteAddr.
type clientIPHost interface {
ClientIP(*http.Request) string
}
// RouteInfo is one registered route as the Host reports it: the HTTP method,
// the pattern as registered (with {param} segments), the plugin that
// registered it and its middleware names in order.
type RouteInfo struct {
Method string
Pattern string
PluginID string
Middleware []string
}
// PluginID is the pseudo-plugin id pier's own routes are registered under in
// the route table.
const PluginID = "summercms.pier"