Compare commits

..

No commits in common. "b53658e0389f5d612dfe30ddb5b7fdeaeb66987d" and "762f90adf669a55350d975333f1f722546d69e74" have entirely different histories.

4 changed files with 7 additions and 49 deletions

View File

@ -232,7 +232,7 @@ func main() {
rp := &atRequestParser{}
bsh := handlers.NewBaseSessionHandler(cfg, rs, stateStore, userdataStore, rp, hl)
sh := httpserver.ToSessionHandler(bsh, httpserver.WithAtOutput())
sh := httpserver.ToSessionHandler(bsh)
s := &http.Server{
Addr: fmt.Sprintf("%s:%s", host, strconv.Itoa(int(port))),
Handler: sh,

View File

@ -1,15 +1,13 @@
package handlers
import (
"io"
"git.defalsify.org/vise.git/db"
"git.defalsify.org/vise.git/engine"
"git.defalsify.org/vise.git/persist"
"git.defalsify.org/vise.git/resource"
"git.defalsify.org/vise.git/persist"
"git.defalsify.org/vise.git/db"
"git.grassecon.net/urdt/ussd/internal/handlers/ussd"
"git.grassecon.net/urdt/ussd/internal/storage"
"git.grassecon.net/urdt/ussd/internal/handlers/ussd"
)
type BaseSessionHandler struct {
@ -90,25 +88,6 @@ func(f *BaseSessionHandler) Output(rqs RequestSession) (RequestSession, error)
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) {
defer f.provider.Put(rqs.Config.SessionId, rqs.Storage)
return rqs, rqs.Engine.Finish()

View File

@ -51,7 +51,6 @@ type RequestHandler interface {
GetEngine(cfg engine.Config, rs resource.Resource, pe *persist.Persister) engine.Engine
Process(rs RequestSession) (RequestSession, error)
Output(rs RequestSession) (RequestSession, error)
AtOutput(rs RequestSession) (RequestSession, error)
Reset(rs RequestSession) (RequestSession, error)
Shutdown()
}

View File

@ -43,30 +43,14 @@ func(rp *DefaultRequestParser) GetInput(rq any) ([]byte, error) {
return v, nil
}
type SessionHandlerOption func(*SessionHandler)
func WithAtOutput() SessionHandlerOption {
return func(sh *SessionHandler) {
sh.useAtOutput = true
}
}
type SessionHandler struct {
handlers.RequestHandler
useAtOutput bool
}
func ToSessionHandler(h handlers.RequestHandler, opts ...SessionHandlerOption) *SessionHandler {
sh := &SessionHandler{
func ToSessionHandler(h handlers.RequestHandler) *SessionHandler {
return &SessionHandler{
RequestHandler: h,
useAtOutput: false,
}
for _, opt := range opts {
opt(sh)
}
return sh
}
func(f *SessionHandler) writeError(w http.ResponseWriter, code int, err error) {
@ -124,11 +108,7 @@ func(f *SessionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(200)
w.Header().Set("Content-Type", "text/plain")
if f.useAtOutput {
rqs, err = f.AtOutput(rqs)
} else {
rqs, err = f.Output(rqs)
}
if err != nil {
f.writeError(w, 500, err)
return