sse

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BFFAuthCookie added in v0.15.0

type BFFAuthCookie struct {
	Name     string
	Path     string
	Domain   string
	Secure   bool
	HttpOnly bool
	SameSite http.SameSite
	MaxAge   int
}

BFFAuthCookie defines cookie attributes used for the BFF auth session id (opaque grant id).

type BFFCookie added in v0.15.0

type BFFCookie struct {
	Name     string
	Path     string
	Domain   string
	Secure   bool
	HttpOnly bool
	SameSite http.SameSite
	MaxAge   int
}

BFFCookie defines cookie attributes used to carry the session id.

type Handler

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

Handler represents a server-side newNandler for SSE and message transport.

func New

func New(newHandler transport.NewHandler, options ...Option) *Handler

New creates a new Handler instance with the provided options.

func (*Handler) ServeHTTP

func (s *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface.

type Option

type Option func(t *Options)

func WithAuthStore added in v0.15.0

func WithAuthStore(store auth.Store) Option

WithAuthStore configures the durable store for BFF auth grants.

func WithBFFAuthCookie added in v0.15.0

func WithBFFAuthCookie(c *BFFAuthCookie) Option

WithBFFAuthCookie configures the cookie used to carry the BFF auth grant id.

func WithBFFAuthCookieUseTopDomain added in v0.15.0

func WithBFFAuthCookieUseTopDomain(v bool) Option

WithBFFAuthCookieUseTopDomain enables auto Domain=eTLD+1 for the auth cookie when Domain is empty.

func WithBFFCookieSession added in v0.15.0

func WithBFFCookieSession(c *BFFCookie) Option

WithBFFCookieSession enables cookie-based session id for BFF deployments.

func WithBFFCookieUseTopDomain added in v0.15.0

func WithBFFCookieUseTopDomain(v bool) Option

WithBFFCookieUseTopDomain enables auto setting cookie Domain to eTLD+1 derived from request host.

func WithCORSAllowCredentials added in v0.15.0

func WithCORSAllowCredentials(v bool) Option

WithCORSAllowCredentials toggles Access-Control-Allow-Credentials and credentialed requests.

func WithCORSAllowedOrigins added in v0.15.0

func WithCORSAllowedOrigins(origins []string) Option

WithCORSAllowedOrigins sets the allowed origins for CORS (must not be "*" when AllowCredentials is true).

func WithCleanupInterval added in v0.15.0

func WithCleanupInterval(d time.Duration) Option

WithCleanupInterval sets how often the cleanup sweeper runs.

func WithIdleTTL added in v0.15.0

func WithIdleTTL(d time.Duration) Option

WithIdleTTL sets the idle timeout for sessions.

func WithKeepAliveInterval added in v0.16.2

func WithKeepAliveInterval(d time.Duration) Option

WithKeepAliveInterval sets the interval for SSE keepalive frames on the GET stream. Set to 0 or negative to disable.

func WithLogoutAllPath added in v0.15.0

func WithLogoutAllPath(path string) Option

WithLogoutAllPath sets an optional path to revoke the BFF auth grant (logout all sessions).

func WithMaxEventBuffer added in v0.15.0

func WithMaxEventBuffer(n int) Option

WithMaxEventBuffer sets the default event buffer size used for resumability.

func WithMaxLifetime added in v0.15.0

func WithMaxLifetime(d time.Duration) Option

WithMaxLifetime sets the hard cap on session lifetime.

func WithMessageURI

func WithMessageURI(messageURI string) Option

WithMessageURI sets the message URI for the transport

func WithOnSessionClose added in v0.15.0

func WithOnSessionClose(fn func(*base.Session)) Option

WithOnSessionClose registers a hook invoked when a session is finally closed.

func WithOverflowPolicy added in v0.15.0

func WithOverflowPolicy(p base.OverflowPolicy) Option

WithOverflowPolicy sets the event buffer overflow policy.

func WithReconnectGrace added in v0.15.0

func WithReconnectGrace(d time.Duration) Option

WithReconnectGrace sets the grace period during which a detached session is kept for reconnection.

func WithRehydrateOnHandshake added in v0.15.0

func WithRehydrateOnHandshake(v bool) Option

WithRehydrateOnHandshake toggles using the auth cookie to mint a new MCP session when no session id is provided.

func WithRemovalPolicy added in v0.15.0

func WithRemovalPolicy(p base.RemovalPolicy) Option

WithRemovalPolicy sets the session removal policy.

func WithSessionStore added in v0.15.0

func WithSessionStore(store base.SessionStore) Option

WithSessionStore injects a custom SessionStore implementation.

func WithSseSessionLocation added in v0.5.1

func WithSseSessionLocation(location *session.Location) Option

WithSseSessionLocation sets the optional sessionIdLocation for the transport, used for constructing full URIs

func WithStreamingSessionLocation added in v0.5.1

func WithStreamingSessionLocation(location *session.Location) Option

WithStreamingSessionLocation sets the optional sessionIdLocation for the transport, used for constructing full URIs

func WithURI added in v0.5.3

func WithURI(sseURI string) Option

WithURI sets the SSE URI for the transport

type Options added in v0.5.3

type Options struct {
	MessageURI               string
	URI                      string
	SessionLocation          *session.Location // Optional sessionIdLocation for the transport, used for constructing full URIs
	StreamingSessionLocation *session.Location // Optional sessionIdLocation for the transport, used for constructing full URIs

	// Lifecycle controls
	ReconnectGrace  time.Duration
	IdleTTL         time.Duration
	MaxLifetime     time.Duration
	CleanupInterval time.Duration
	MaxEventBuffer  int
	OnSessionClose  func(*base.Session)
	RemovalPolicy   base.RemovalPolicy
	OverflowPolicy  base.OverflowPolicy
	// Optional custom session store (e.g., Redis-backed). Defaults to in-memory.
	Store base.SessionStore

	// BFF cookie-based session id (optional, disabled by default)
	CookieSession *BFFCookie
	// CORS settings for browsers
	AllowedOrigins   []string
	AllowCredentials bool

	// If true and CookieSession.Domain is empty, set cookie Domain to the request's top domain (eTLD+1).
	CookieUseTopDomain bool

	// BFF auth (server-held) grant
	AuthStore              auth.Store
	AuthCookie             *BFFAuthCookie
	AuthCookieUseTopDomain bool
	RehydrateOnHandshake   bool
	LogoutAllPath          string

	// KeepAliveInterval controls emission of SSE keepalive frames on the
	// long-lived GET stream. Zero or negative disables keepalives.
	KeepAliveInterval time.Duration
}

Options represents SSE options

Jump to

Keyboard shortcuts

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