From 6dbe6ec436a4290bb97883204d205be254cbd943 Mon Sep 17 00:00:00 2001 From: zongor Date: Fri, 12 Jul 2024 22:37:22 -0400 Subject: [PATCH] add ability to handle other requets than GET --- examples/webassembly-example/server.vqe | 4 ++++ varaq/interpreter.go | 22 ++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/examples/webassembly-example/server.vqe b/examples/webassembly-example/server.vqe index 7eaca94..9a5df3d 100644 --- a/examples/webassembly-example/server.vqe +++ b/examples/webassembly-example/server.vqe @@ -2,6 +2,10 @@ (* get the request info *) argv shatter + (* if its a get request we want to ignore the request body *) + "GET" streq? + { pop } ifyes + (* check to see if we have the root route, if so return index.html *) dup "/" streq? choose diff --git a/varaq/interpreter.go b/varaq/interpreter.go index 665149c..2d7f160 100644 --- a/varaq/interpreter.go +++ b/varaq/interpreter.go @@ -1068,19 +1068,25 @@ func Interpret(code Expr, argv []string, w io.Writer) error { if e != nil { return e } + if fun.Tok != FUNCTION { + return fmt.Errorf("cannot `servehttp` exptected a function to serve @%v", idx) + } http.ListenAndServe(str.Value.(string), http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { req := make([]string, 0) - req = append(req, r.RequestURI) - - if fun.Tok == FUNCTION { - zerr := Interpret(fun, req, w) - if zerr != nil { - fmt.Println(zerr) - } - } else { + b, err := ioutil.ReadAll(r.Body) + if err != nil { + fmt.Println(err) return } + req = append(req, r.RequestURI) + req = append(req, string(b)) + req = append(req, r.Method) + + err = Interpret(fun, req, w) + if err != nil { + fmt.Println(err) + } })) case READALL: str, e := pop()