add ability to handle other requets than GET
This commit is contained in:
parent
81b765a1b2
commit
6dbe6ec436
|
@ -2,6 +2,10 @@
|
||||||
(* get the request info *)
|
(* get the request info *)
|
||||||
argv shatter
|
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 *)
|
(* check to see if we have the root route, if so return index.html *)
|
||||||
dup "/" streq?
|
dup "/" streq?
|
||||||
choose
|
choose
|
||||||
|
|
|
@ -1068,19 +1068,25 @@ func Interpret(code Expr, argv []string, w io.Writer) error {
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return e
|
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) {
|
http.ListenAndServe(str.Value.(string), http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
req := make([]string, 0)
|
req := make([]string, 0)
|
||||||
req = append(req, r.RequestURI)
|
b, err := ioutil.ReadAll(r.Body)
|
||||||
|
if err != nil {
|
||||||
if fun.Tok == FUNCTION {
|
fmt.Println(err)
|
||||||
zerr := Interpret(fun, req, w)
|
|
||||||
if zerr != nil {
|
|
||||||
fmt.Println(zerr)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return
|
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:
|
case READALL:
|
||||||
str, e := pop()
|
str, e := pop()
|
||||||
|
|
Loading…
Reference in New Issue