From 3e292583fa3db18c2d6bca8ff6d8250c93e534ab Mon Sep 17 00:00:00 2001 From: travisturner Date: Tue, 14 Jan 2014 15:30:35 -0600 Subject: [PATCH] add support for db in post query --- core/http.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/core/http.go b/core/http.go index 5aafaa786..43ba2ca2b 100644 --- a/core/http.go +++ b/core/http.go @@ -2,7 +2,6 @@ package core import ( "encoding/json" - "io/ioutil" "log" "net/http" "pilosa/config" @@ -59,15 +58,24 @@ func (self *WebService) HandleQuery(w http.ResponseWriter, r *http.Request) { http.Error(w, "Only POST allowed", http.StatusMethodNotAllowed) return } - body, err := ioutil.ReadAll(r.Body) - defer r.Body.Close() + err := r.ParseForm() if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + + database_name := r.Form.Get("db") + pql := r.Form.Get("pql") + + defer r.Body.Close() + if pql == "" { http.Error(w, "Error reading POST data", http.StatusBadRequest) return } // TODO: we need to get the database name from the query string (for now, hard-coded) - database_name := "main" - pql := string(body) + if database_name == "" { + database_name = "main" //TODO pull this from config DEFAULT + } results := self.service.Executor.RunPQL(database_name, pql) encoder := json.NewEncoder(w)