Commit 32aaf497 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Add session delete api for requestor in library and server

parent 2b156c7e
......@@ -110,6 +110,15 @@ func GetSessionResult(token string) *server.SessionResult {
return session.result
}
func CancelSession(token string) error {
session := sessions.get(token)
if session == nil {
return errors.New("Unknown session, can't cancel")
}
session.handleDelete()
return nil
}
func HandleProtocolMessage(
path string,
method string,
......
......@@ -32,6 +32,10 @@ func GetSessionResult(token string) *server.SessionResult {
return backend.GetSessionResult(token)
}
func CancelSession(token string) error {
return backend.CancelSession(token)
}
func HttpHandlerFunc(prefix string) http.HandlerFunc {
if len(prefix) != 0 && prefix[0] != '/' {
prefix = "/" + prefix
......
......@@ -63,6 +63,7 @@ func Handler(config *Configuration) (http.Handler, error) {
// Server routes
router.Post("/session", handleCreate)
router.Delete("/session/{token}", handleDelete)
router.Get("/session/{token}/status", handleStatus)
router.Get("/session/{token}/result", handleResult)
......@@ -141,6 +142,13 @@ func handleStatus(w http.ResponseWriter, r *http.Request) {
server.WriteJson(w, res.Status)
}
func handleDelete(w http.ResponseWriter, r *http.Request) {
err := irmarequestor.CancelSession(chi.URLParam(r, "token"))
if err != nil {
server.WriteError(w, server.ErrorSessionUnknown, "")
}
}
func handleResult(w http.ResponseWriter, r *http.Request) {
res := irmarequestor.GetSessionResult(chi.URLParam(r, "token"))
if res == nil {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment