Get without id == trace since browsers dont support trace

master
Bel LaPointe 2020-07-24 23:25:32 -06:00
parent 55d8cf5d43
commit 663579aeae
2 changed files with 18 additions and 2 deletions

View File

@ -44,8 +44,7 @@ func who(g storage.Graph, w http.ResponseWriter, r *http.Request) error {
func whoGet(namespace string, g storage.Graph, w http.ResponseWriter, r *http.Request) error {
id, err := getID(r)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
return whoTrace(namespace, g, w, r)
}
_, light := r.URL.Query()["light"]

View File

@ -254,6 +254,23 @@ func TestWho(t *testing.T) {
t.Logf("%+v", v)
})
t.Run("get without id == trace real", func(t *testing.T) {
r := httptest.NewRequest(http.MethodGet, "/who?namespace=col", nil)
w := httptest.NewRecorder()
handler.ServeHTTP(w, r)
if w.Code != http.StatusOK {
t.Fatalf("%d: %s", w.Code, w.Body.Bytes())
}
var v []string
if err := json.Unmarshal(w.Body.Bytes(), &v); err != nil {
t.Fatalf("%v: %s", err, w.Body.Bytes())
}
if len(v) < 5 {
t.Fatal(len(v))
}
t.Logf("%+v", v)
})
t.Run("trace real sorted asc/desc name", func(t *testing.T) {
for _, order := range []string{"1", "-1"} {
r := httptest.NewRequest(http.MethodTrace, "/who?namespace=col&sort=name&order="+order, nil)