africas-talking #50
@ -1,8 +1,6 @@
|
|||||||
package handlers
|
package handlers
|
||||||
lash marked this conversation as resolved
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
|
|
||||||
"git.defalsify.org/vise.git/db"
|
"git.defalsify.org/vise.git/db"
|
||||||
"git.defalsify.org/vise.git/engine"
|
"git.defalsify.org/vise.git/engine"
|
||||||
"git.defalsify.org/vise.git/persist"
|
"git.defalsify.org/vise.git/persist"
|
||||||
@ -90,25 +88,6 @@ func(f *BaseSessionHandler) Output(rqs RequestSession) (RequestSession, error)
|
|||||||
return rqs, err
|
return rqs, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *BaseSessionHandler) AtOutput(rqs RequestSession) (RequestSession, error) {
|
|
||||||
var err error
|
|
||||||
var prefix string
|
|
||||||
|
|
||||||
if rqs.Continue {
|
|
||||||
prefix = "CON "
|
|
||||||
} else {
|
|
||||||
prefix = "END "
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = io.WriteString(rqs.Writer, prefix)
|
|
||||||
if err != nil {
|
|
||||||
return rqs, err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = rqs.Engine.WriteResult(rqs.Ctx, rqs.Writer)
|
|
||||||
return rqs, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func(f *BaseSessionHandler) Reset(rqs RequestSession) (RequestSession, error) {
|
func(f *BaseSessionHandler) Reset(rqs RequestSession) (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()
|
||||||
Alfred-mk marked this conversation as resolved
Outdated
lash
commented
This method should not exist in the base handler. Please EXTEND the handler to adapt it to your needs. In fact, you probably need to extend the internal/http/server.go SessionHandler instead, since it in turn extends this, and also provides other functionality you need. BaseSessionHandler -> http.SessionHandler -> at.SessionHandler This method should not exist in the base handler. Please EXTEND the handler to adapt it to your needs.
In fact, you probably need to extend the internal/http/server.go SessionHandler instead, since it in turn extends this, and also provides other functionality you need.
BaseSessionHandler -> http.SessionHandler -> at.SessionHandler
|
|||||||
|
@ -51,7 +51,6 @@ type RequestHandler interface {
|
|||||||
GetEngine(cfg engine.Config, rs resource.Resource, pe *persist.Persister) engine.Engine
|
GetEngine(cfg engine.Config, rs resource.Resource, pe *persist.Persister) engine.Engine
|
||||||
Process(rs RequestSession) (RequestSession, error)
|
Process(rs RequestSession) (RequestSession, error)
|
||||||
Output(rs RequestSession) (RequestSession, error)
|
Output(rs RequestSession) (RequestSession, error)
|
||||||
AtOutput(rs RequestSession) (RequestSession, error)
|
|
||||||
Reset(rs RequestSession) (RequestSession, error)
|
Reset(rs RequestSession) (RequestSession, error)
|
||||||
Shutdown()
|
Shutdown()
|
||||||
}
|
}
|
||||||
|
@ -43,30 +43,14 @@ func(rp *DefaultRequestParser) GetInput(rq any) ([]byte, error) {
|
|||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type SessionHandlerOption func(*SessionHandler)
|
|
||||||
|
|
||||||
func WithAtOutput() SessionHandlerOption {
|
|
||||||
return func(sh *SessionHandler) {
|
|
||||||
sh.useAtOutput = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type SessionHandler struct {
|
type SessionHandler struct {
|
||||||
handlers.RequestHandler
|
handlers.RequestHandler
|
||||||
useAtOutput bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToSessionHandler(h handlers.RequestHandler, opts ...SessionHandlerOption) *SessionHandler {
|
func ToSessionHandler(h handlers.RequestHandler) *SessionHandler {
|
||||||
sh := &SessionHandler{
|
return &SessionHandler{
|
||||||
RequestHandler: h,
|
RequestHandler: h,
|
||||||
useAtOutput: false,
|
|
||||||
}
|
}
|
||||||
for _, opt := range opts {
|
|
||||||
opt(sh)
|
|
||||||
}
|
|
||||||
return sh
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func(f *SessionHandler) writeError(w http.ResponseWriter, code int, err error) {
|
func(f *SessionHandler) writeError(w http.ResponseWriter, code int, err error) {
|
||||||
@ -84,6 +68,7 @@ func(f *SessionHandler) writeError(w http.ResponseWriter, code int, err error) {
|
|||||||
func(f *SessionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
func(f *SessionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
var code int
|
var code int
|
||||||
var err error
|
var err error
|
||||||
|
var perr error
|
||||||
|
|
||||||
rqs := handlers.RequestSession{
|
rqs := handlers.RequestSession{
|
||||||
Ctx: req.Context(),
|
Ctx: req.Context(),
|
||||||
@ -124,19 +109,14 @@ func(f *SessionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
|
|
||||||
w.WriteHeader(200)
|
w.WriteHeader(200)
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
w.Header().Set("Content-Type", "text/plain")
|
||||||
if f.useAtOutput {
|
|
||||||
rqs, err = f.AtOutput(rqs)
|
|
||||||
} else {
|
|
||||||
rqs, err = f.Output(rqs)
|
rqs, err = f.Output(rqs)
|
||||||
}
|
rqs, perr = f.Reset(rqs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f.writeError(w, 500, err)
|
f.writeError(w, 500, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if perr != nil {
|
||||||
rqs, err = f.Reset(rqs)
|
f.writeError(w, 500, perr)
|
||||||
if err != nil {
|
|
||||||
f.writeError(w, 500, err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user
It would be better to have this PR against my async branch, because here we cannot see the differences....
I've updated the PR to reflect this