Rename session handler to request handler

This commit is contained in:
lash 2025-01-12 10:40:23 +00:00
parent dcf777bf08
commit 611c5a8dfc
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
3 changed files with 21 additions and 21 deletions

View File

@ -16,7 +16,7 @@ var (
logg = logging.NewVanilla().WithDomain("visedriver.session") logg = logging.NewVanilla().WithDomain("visedriver.session")
) )
type BaseSessionHandler struct { type BaseRequestHandler struct {
cfgTemplate engine.Config cfgTemplate engine.Config
rp request.RequestParser rp request.RequestParser
rs resource.Resource rs resource.Resource
@ -24,9 +24,9 @@ type BaseSessionHandler struct {
provider storage.StorageProvider 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 NewBaseRequestHandler(cfg engine.Config, rs resource.Resource, stateDb db.Db, userdataDb db.Db, rp request.RequestParser, hn *handlers.Handlers) *BaseRequestHandler {
func NewBaseSessionHandler(cfg engine.Config, rs resource.Resource, stateDb db.Db, userdataDb db.Db, rp request.RequestParser, hn entry.EntryHandler) *BaseSessionHandler { func NewBaseRequestHandler(cfg engine.Config, rs resource.Resource, stateDb db.Db, userdataDb db.Db, rp request.RequestParser, hn entry.EntryHandler) *BaseRequestHandler {
return &BaseSessionHandler{ return &BaseRequestHandler{
cfgTemplate: cfg, cfgTemplate: cfg,
rs: rs, rs: rs,
hn: hn, 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() err := f.provider.Close()
if err != nil { if err != nil {
logg.Errorf("handler shutdown error", "err", err) 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 := engine.NewEngine(cfg, rs)
en = en.WithPersister(pr) en = en.WithPersister(pr)
return en 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 r bool
var err error var err error
var ok bool var ok bool
@ -96,21 +96,21 @@ func(f *BaseSessionHandler) Process(rqs request.RequestSession) (request.Request
return rqs, nil 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 var err error
_, err = rqs.Engine.Flush(rqs.Ctx, rqs.Writer) _, err = rqs.Engine.Flush(rqs.Ctx, rqs.Writer)
return rqs, err 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) defer f.provider.Put(rqs.Config.SessionId, rqs.Storage)
return rqs, rqs.Engine.Finish() return rqs, rqs.Engine.Finish()
} }
func (f *BaseSessionHandler) GetConfig() engine.Config { func (f *BaseRequestHandler) GetConfig() engine.Config {
return f.cfgTemplate return f.cfgTemplate
} }
func(f *BaseSessionHandler) GetRequestParser() request.RequestParser { func(f *BaseRequestHandler) GetRequestParser() request.RequestParser {
return f.rp return f.rp
} }

View File

@ -13,12 +13,12 @@ var (
logg = logging.NewVanilla().WithDomain("visedriver.http.session") logg = logging.NewVanilla().WithDomain("visedriver.http.session")
) )
// HTTPSessionHandler implements the session handler for HTTP // HTTPRequestHandler implements the session handler for HTTP
type HTTPSessionHandler struct { type HTTPRequestHandler struct {
request.RequestHandler 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() s := err.Error()
w.Header().Set("Content-Length", strconv.Itoa(len(s))) w.Header().Set("Content-Length", strconv.Itoa(len(s)))
w.WriteHeader(code) w.WriteHeader(code)
@ -29,13 +29,13 @@ func (f *HTTPSessionHandler) WriteError(w http.ResponseWriter, code int, err err
} }
} }
func NewHTTPSessionHandler(h request.RequestHandler) *HTTPSessionHandler { func NewHTTPRequestHandler(h request.RequestHandler) *HTTPRequestHandler {
return &HTTPSessionHandler{ return &HTTPRequestHandler{
RequestHandler: h, 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 code int
var err error var err error
var perr error var perr error

View File

@ -24,7 +24,7 @@ func (e *errorReader) Read(p []byte) (n int, err error) {
return 0, errors.New("read error") return 0, errors.New("read error")
} }
func TestSessionHandler_ServeHTTP(t *testing.T) { func TestRequestHandler_ServeHTTP(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
sessionID string sessionID string
@ -99,7 +99,7 @@ func TestSessionHandler_ServeHTTP(t *testing.T) {
}, },
} }
sessionHandler := &HTTPSessionHandler{ sessionHandler := &HTTPRequestHandler{
RequestHandler: mockRequestHandler, RequestHandler: mockRequestHandler,
} }
@ -118,8 +118,8 @@ func TestSessionHandler_ServeHTTP(t *testing.T) {
} }
} }
func TestSessionHandler_WriteError(t *testing.T) { func TestRequestHandler_WriteError(t *testing.T) {
handler := &HTTPSessionHandler{} handler := &HTTPRequestHandler{}
mockWriter := &httpmocks.MockWriter{} mockWriter := &httpmocks.MockWriter{}
err := errors.New("test error") err := errors.New("test error")