03568c88e3
- frontend/functions/core/format_datetime_short.md - frontend/functions/core/format_datetime_short.test.ts - frontend/functions/core/format_datetime_short.ts - frontend/functions/core/format_duration.md - frontend/functions/core/format_duration.test.ts - frontend/functions/core/format_duration.ts - frontend/functions/core/month_grid.md - frontend/functions/core/month_grid.test.ts - frontend/functions/core/month_grid.ts - frontend/functions/core/string_hash_palette.md - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
20 lines
634 B
Go
20 lines
634 B
Go
package infra
|
|
|
|
import "net/http"
|
|
|
|
// SessionTokenExtract extracts a session token from the request.
|
|
// It checks the cookie named cookieName first; if present and non-empty,
|
|
// that value is returned. Otherwise it checks the Authorization header
|
|
// for a "Bearer <token>" prefix and returns the token part.
|
|
// Returns "" if no token is found in either source.
|
|
func SessionTokenExtract(r *http.Request, cookieName string) string {
|
|
if c, err := r.Cookie(cookieName); err == nil && c.Value != "" {
|
|
return c.Value
|
|
}
|
|
auth := r.Header.Get("Authorization")
|
|
if len(auth) > 7 && auth[:7] == "Bearer " {
|
|
return auth[7:]
|
|
}
|
|
return ""
|
|
}
|