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")
)
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
}

View File

@ -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

View File

@ -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")