From 611c5a8dfc802262a4400afde59a0e85c4592b6f Mon Sep 17 00:00:00 2001 From: lash Date: Sun, 12 Jan 2025 10:40:23 +0000 Subject: [PATCH] Rename session handler to request handler --- session/base.go | 22 +++++++++++----------- session/http/server.go | 12 ++++++------ session/http/server_test.go | 8 ++++---- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/session/base.go b/session/base.go index 99176b6..126a79a 100644 --- a/session/base.go +++ b/session/base.go @@ -16,7 +16,7 @@ var ( logg = logging.NewVanilla().WithDomain("visedriver.session") ) -type BaseSessionHandler struct { +type BaseRequestHandler struct { cfgTemplate engine.Config rp request.RequestParser rs resource.Resource @@ -24,9 +24,9 @@ type BaseSessionHandler struct { provider storage.StorageProvider } -//func NewBaseSessionHandler(cfg engine.Config, rs resource.Resource, stateDb db.Db, userdataDb db.Db, rp request.RequestParser, hn *handlers.Handlers) *BaseSessionHandler { -func NewBaseSessionHandler(cfg engine.Config, rs resource.Resource, stateDb db.Db, userdataDb db.Db, rp request.RequestParser, hn entry.EntryHandler) *BaseSessionHandler { - return &BaseSessionHandler{ +//func NewBaseRequestHandler(cfg engine.Config, rs resource.Resource, stateDb db.Db, userdataDb db.Db, rp request.RequestParser, hn *handlers.Handlers) *BaseRequestHandler { +func NewBaseRequestHandler(cfg engine.Config, rs resource.Resource, stateDb db.Db, userdataDb db.Db, rp request.RequestParser, hn entry.EntryHandler) *BaseRequestHandler { + return &BaseRequestHandler{ cfgTemplate: cfg, rs: rs, hn: hn, @@ -35,20 +35,20 @@ func NewBaseSessionHandler(cfg engine.Config, rs resource.Resource, stateDb db.D } } -func (f *BaseSessionHandler) Shutdown() { +func (f *BaseRequestHandler) Shutdown() { err := f.provider.Close() if err != nil { logg.Errorf("handler shutdown error", "err", err) } } -func (f *BaseSessionHandler) GetEngine(cfg engine.Config, rs resource.Resource, pr *persist.Persister) engine.Engine { +func (f *BaseRequestHandler) GetEngine(cfg engine.Config, rs resource.Resource, pr *persist.Persister) engine.Engine { en := engine.NewEngine(cfg, rs) en = en.WithPersister(pr) return en } -func(f *BaseSessionHandler) Process(rqs request.RequestSession) (request.RequestSession, error) { +func(f *BaseRequestHandler) Process(rqs request.RequestSession) (request.RequestSession, error) { var r bool var err error var ok bool @@ -96,21 +96,21 @@ func(f *BaseSessionHandler) Process(rqs request.RequestSession) (request.Request return rqs, nil } -func(f *BaseSessionHandler) Output(rqs request.RequestSession) (request.RequestSession, error) { +func(f *BaseRequestHandler) Output(rqs request.RequestSession) (request.RequestSession, error) { var err error _, err = rqs.Engine.Flush(rqs.Ctx, rqs.Writer) return rqs, err } -func(f *BaseSessionHandler) Reset(rqs request.RequestSession) (request.RequestSession, error) { +func(f *BaseRequestHandler) Reset(rqs request.RequestSession) (request.RequestSession, error) { defer f.provider.Put(rqs.Config.SessionId, rqs.Storage) return rqs, rqs.Engine.Finish() } -func (f *BaseSessionHandler) GetConfig() engine.Config { +func (f *BaseRequestHandler) GetConfig() engine.Config { return f.cfgTemplate } -func(f *BaseSessionHandler) GetRequestParser() request.RequestParser { +func(f *BaseRequestHandler) GetRequestParser() request.RequestParser { return f.rp } diff --git a/session/http/server.go b/session/http/server.go index 80f4357..92d4fa6 100644 --- a/session/http/server.go +++ b/session/http/server.go @@ -13,12 +13,12 @@ var ( logg = logging.NewVanilla().WithDomain("visedriver.http.session") ) -// HTTPSessionHandler implements the session handler for HTTP -type HTTPSessionHandler struct { +// HTTPRequestHandler implements the session handler for HTTP +type HTTPRequestHandler struct { request.RequestHandler } -func (f *HTTPSessionHandler) WriteError(w http.ResponseWriter, code int, err error) { +func (f *HTTPRequestHandler) WriteError(w http.ResponseWriter, code int, err error) { s := err.Error() w.Header().Set("Content-Length", strconv.Itoa(len(s))) w.WriteHeader(code) @@ -29,13 +29,13 @@ func (f *HTTPSessionHandler) WriteError(w http.ResponseWriter, code int, err err } } -func NewHTTPSessionHandler(h request.RequestHandler) *HTTPSessionHandler { - return &HTTPSessionHandler{ +func NewHTTPRequestHandler(h request.RequestHandler) *HTTPRequestHandler { + return &HTTPRequestHandler{ RequestHandler: h, } } -func (hh *HTTPSessionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { +func (hh *HTTPRequestHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { var code int var err error var perr error diff --git a/session/http/server_test.go b/session/http/server_test.go index 2987c24..f7ef778 100644 --- a/session/http/server_test.go +++ b/session/http/server_test.go @@ -24,7 +24,7 @@ func (e *errorReader) Read(p []byte) (n int, err error) { return 0, errors.New("read error") } -func TestSessionHandler_ServeHTTP(t *testing.T) { +func TestRequestHandler_ServeHTTP(t *testing.T) { tests := []struct { name string sessionID string @@ -99,7 +99,7 @@ func TestSessionHandler_ServeHTTP(t *testing.T) { }, } - sessionHandler := &HTTPSessionHandler{ + sessionHandler := &HTTPRequestHandler{ RequestHandler: mockRequestHandler, } @@ -118,8 +118,8 @@ func TestSessionHandler_ServeHTTP(t *testing.T) { } } -func TestSessionHandler_WriteError(t *testing.T) { - handler := &HTTPSessionHandler{} +func TestRequestHandler_WriteError(t *testing.T) { + handler := &HTTPRequestHandler{} mockWriter := &httpmocks.MockWriter{} err := errors.New("test error")