mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-03 01:41:44 +00:00
feat: add User-Agent and Platform to session
This commit is contained in:
+20
-7
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/sessions"
|
||||
@@ -45,16 +46,28 @@ func SessionMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func defaultSession(id string, s *sessions.Session) *session {
|
||||
return &session{
|
||||
session: s,
|
||||
id: id,
|
||||
origin: "",
|
||||
address: "",
|
||||
chainID: "",
|
||||
func buildSession(c echo.Context, id string) *Session {
|
||||
return &Session{
|
||||
ID: id,
|
||||
Origin: getOrigin(c.Request().Header.Get("Host")),
|
||||
UserAgent: c.Request().Header.Get("Sec-Ch-Ua"),
|
||||
Platform: c.Request().Header.Get("Sec-Ch-Ua-Platform"),
|
||||
Address: c.Request().Header.Get("X-Sonr-Address"),
|
||||
ChainID: "",
|
||||
}
|
||||
}
|
||||
|
||||
func getOrigin(o string) string {
|
||||
if o == "" {
|
||||
return ""
|
||||
}
|
||||
u, err := url.Parse(o)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return u.Hostname()
|
||||
}
|
||||
|
||||
func getSessionID(ctx context.Context) (string, error) {
|
||||
sessionID, ok := ctx.Value(ctxKeySessionID{}).(string)
|
||||
if !ok || sessionID == "" {
|
||||
|
||||
Reference in New Issue
Block a user