diff options
Diffstat (limited to 'worker.go')
| -rw-r--r-- | worker.go | 31 |
1 files changed, 25 insertions, 6 deletions
@@ -93,14 +93,22 @@ func (w *Worker) Listen(queue chan any) { } w.lua.PushFromRef(w.routes[r.route]) - w.lua.PushString(r.request.Method) - w.lua.PushString(r.request.URL.Path) + res := make(map[string]any) + res["method"] = r.request.Method + res["path"] = r.request.URL.Path - fh := make(map[string]string) + fh := make(map[string]any) for k := range r.request.Header { fh[k] = r.request.Header.Get(k) } - w.lua.PushStringTable(fh) + res["headers"] = fh + + flatQr := make(map[string]any) + qr := r.request.URL.Query() + for k := range qr { + flatQr[k] = qr.Get(k) + } + res["query"] = flatQr body, err := io.ReadAll(r.request.Body) if err != nil { @@ -112,9 +120,20 @@ func (w *Worker) Listen(queue chan any) { log.Println("could not read a request body:", err) return } - w.lua.PushString(string(body)) + res["body"] = string(body) + + err = w.lua.PushObject(res) + if err != nil { + r.result <- &HTTPResponse { + Code: 500, + Headers: make(map[string]string), + Body: "server error", + } + log.Println("could not form a request to lua:", err) + return + } - err = w.lua.PCall(4, 3) + err = w.lua.PCall(1, 3) if err != nil { r.result <- &HTTPResponse { |
