feat(19.7-02): Redis sessions, event fan-out, stateless protocol path and resource metadata

- store_redis.go: records with PX TTLs, per-binding sets, pub/sub events,
  opened lazily from redis.url under cooler's prefix (nothing dials at mount)
- events.go: pact.MCPSubjectChanged republished through the store; every
  instance recomputes the subject's sessions and stateless servers
  (list_changed) or ends them on revocation; the link cache is dropped
- stateless.go: the SDK's stateless handler over per-identity servers for
  2026-07-28 clients, routed by the protocol header or server/discover
- prm.go: RFC 9728 metadata at both well-known paths; long GET streams
  re-verify their bearer every minute
- TestPierSessionsSmoke, TestPierFanOutSmoke, TestPierStatelessSmoke on
  miniredis; README features, configuration and operational notes
This commit is contained in:
Jakub Zych
2026-10-22 18:23:43 +02:00
parent cfdbaf0e47
commit 806e87c510
11 changed files with 1133 additions and 32 deletions

View File

@@ -10,6 +10,7 @@ import (
"io"
"net/http"
"slices"
"strings"
"sync"
"sync/atomic"
"time"
@@ -346,9 +347,43 @@ func (sr *sessionRouter) persist(ctx context.Context, ls *localSession) {
}
}
// serveStream serves the standalone GET stream.
// serveStream serves the standalone GET stream and re-verifies its bearer
// every recheck interval on a goroutine that holds the raw bearer only for
// the stream's lifetime; a bearer that no longer resolves to the session's
// binding ends the stream (Pitfall 10). The server's base context ends
// every stream at shutdown.
func (sr *sessionRouter) serveStream(w http.ResponseWriter, r *http.Request, ls *localSession) {
ls.transport.ServeHTTP(w, r)
ctx, cancel := context.WithCancel(r.Context())
defer cancel()
raw := bearerOf(r)
go func() {
ticker := time.NewTicker(sr.p.recheck)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
id, err := sr.p.identities.resolve(ctx, raw)
if err != nil || id.Binding != ls.binding {
logSession(logger(), "stream_closed", ls.id, ls.binding)
cancel()
return
}
_ = sr.p.store.Touch(ctx, ls.id, sr.p.cfg.IdleTTL)
}
}
}()
ls.transport.ServeHTTP(w, r.WithContext(ctx))
}
// bearerOf reads the bearer of a request's Authorization header.
func bearerOf(r *http.Request) string {
fields := strings.Fields(r.Header.Get("Authorization"))
if len(fields) != 2 || !strings.EqualFold(fields[0], "bearer") {
return ""
}
return fields[1]
}
// closeLocal closes and forgets this instance's copy of a session.