diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index 095d77b..dfdbd02 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -28,7 +28,7 @@ import ( ) var ( - logg = logging.NewVanilla().WithDomain("ussdmenuhandler").WithContextKey("session-id") + logg = logging.NewVanilla().WithDomain("ussdmenuhandler").WithContextKey("SessionId") scriptDir = path.Join("services", "registration") translationDir = path.Join(scriptDir, "locale") ) @@ -124,7 +124,7 @@ func (h *Handlers) Init(ctx context.Context, sym string, input []byte) (resource sessionId, ok := ctx.Value("SessionId").(string) if ok { - context.WithValue(ctx, "session-id", sessionId) + ctx = context.WithValue(ctx, "SessionId", sessionId) } flag_admin_privilege, _ := h.flagManager.GetFlag("flag_admin_privilege") diff --git a/internal/http/at/parse.go b/internal/http/at/parse.go index d2696ed..5f27d50 100644 --- a/internal/http/at/parse.go +++ b/internal/http/at/parse.go @@ -15,16 +15,14 @@ import ( ) type ATRequestParser struct { - Context context.Context } -func (arp *ATRequestParser) GetSessionId(rq any) (string, error) { +func (arp *ATRequestParser) GetSessionId(ctx context.Context, rq any) (string, error) { rqv, ok := rq.(*http.Request) if !ok { logg.Warnf("got an invalid request", "req", rq) return "", handlers.ErrInvalidRequest } - // Capture body (if any) for logging body, err := io.ReadAll(rqv.Body) if err != nil { @@ -43,9 +41,9 @@ func (arp *ATRequestParser) GetSessionId(rq any) (string, error) { decodedStr := string(logBytes) sessionId, err := extractATSessionId(decodedStr) if err != nil { - context.WithValue(arp.Context, "at-session-id", sessionId) + ctx = context.WithValue(ctx, "AT-SessionId", sessionId) } - logg.Debugf("Received request:", decodedStr) + logg.DebugCtxf(ctx, "Received request:", decodedStr) } if err := rqv.ParseForm(); err != nil { diff --git a/internal/http/at/server.go b/internal/http/at/server.go index 705ff76..92f76bc 100644 --- a/internal/http/at/server.go +++ b/internal/http/at/server.go @@ -10,7 +10,7 @@ import ( ) var ( - logg = logging.NewVanilla().WithDomain("atserver") + logg = logging.NewVanilla().WithDomain("atserver").WithContextKey("AT-SessionId") ) type ATSessionHandler struct { @@ -34,7 +34,7 @@ func (ash *ATSessionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) rp := ash.GetRequestParser() cfg := ash.GetConfig() - cfg.SessionId, err = rp.GetSessionId(req) + cfg.SessionId, err = rp.GetSessionId(req.Context(), req) if err != nil { logg.ErrorCtxf(rqs.Ctx, "", "header processing error", err) ash.WriteError(w, 400, err) @@ -48,7 +48,7 @@ func (ash *ATSessionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) return } - rqs, err = ash.Process(rqs) + rqs, err = ash.Process(rqs) switch err { case nil: // set code to 200 if no err code = 200 diff --git a/internal/http/server.go b/internal/http/server.go index 9cadfa3..92855b9 100644 --- a/internal/http/server.go +++ b/internal/http/server.go @@ -10,7 +10,7 @@ import ( ) var ( - logg = logging.NewVanilla().WithDomain("httpserver") + logg = logging.NewVanilla().WithDomain("httpserver").WithContextKey("at-session-id") ) type SessionHandler struct { @@ -46,7 +46,7 @@ func (f *SessionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { rp := f.GetRequestParser() cfg := f.GetConfig() - cfg.SessionId, err = rp.GetSessionId(req) + cfg.SessionId, err = rp.GetSessionId(req.Context(), req) if err != nil { logg.ErrorCtxf(rqs.Ctx, "", "header processing error", err) f.WriteError(w, 400, err)