Skip to content

Commit 0d094b4

Browse files
authored
feat: add HeaderSessionType constant and set it in Session middleware (#54)
1 parent a308846 commit 0d094b4

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

common.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import (
1919
)
2020

2121
const (
22-
HeaderAccessKey = "X-Access-Key"
22+
HeaderAccessKey = "X-Access-Key"
23+
HeaderSessionType = "Session-Type"
2324
)
2425

2526
type AccessKeyFunc func(*http.Request) string

middleware.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ func Session(cfg Options) func(next http.Handler) http.Handler {
146146
if _, ok := GetSessionType(ctx); ok {
147147
// Track this as a SpecialKey session for now.
148148
// TODO: Remove once node-gateway SpecialKey support is gone.
149+
w.Header().Set(HeaderSessionType, "SpecialKey")
149150
httplog.SetAttrs(ctx, slog.String("sessionType", "SpecialKey"))
150151
requestsCounter.Inc(sessionLabels{SessionType: "SpecialKey", RateLimited: "false"})
151-
152152
next.ServeHTTP(w, r)
153153
return
154154
}
@@ -185,7 +185,7 @@ func Session(cfg Options) func(next http.Handler) http.Handler {
185185
httplog.SetAttrs(ctx, slog.String("account", accountClaim))
186186

187187
if cfg.UserStore != nil {
188-
user, isAdmin, err := cfg.UserStore.GetUser(ctx, accountClaim)
188+
user, isAdmin, err := cfg.UserStore.GetUser(context.WithValue(ctx, proto.HTTPRequestCtxKey, r), accountClaim)
189189
if err != nil {
190190
cfg.ErrHandler(r, w, err)
191191
return
@@ -260,6 +260,7 @@ func Session(cfg Options) func(next http.Handler) http.Handler {
260260
}
261261

262262
ctx = WithSessionType(ctx, sessionType)
263+
w.Header().Set(HeaderSessionType, sessionType.String())
263264
httplog.SetAttrs(ctx, slog.String("sessionType", sessionType.String()))
264265

265266
ww, ok := w.(middleware.WrapResponseWriter)

0 commit comments

Comments
 (0)