mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-31 04:53:01 +02:00
yangerd: Return {} instead of 404 if no match
This commit is contained in:
@@ -131,10 +131,15 @@ func (s *Server) handleGet(conn net.Conn, req *Request) {
|
||||
|
||||
data := s.tree.Get(key)
|
||||
if data == nil {
|
||||
// An absent subtree is a normal answer for operational data --
|
||||
// the feature is simply not active (e.g. NTP unconfigured).
|
||||
// Answer ok with an empty object rather than an error, so every
|
||||
// client gets "no data" without special-casing. Deliberately
|
||||
// NOT {"<key>": {}}: that would make libyang instantiate the
|
||||
// container, which for presence containers is real data.
|
||||
WriteResponse(conn, &Response{
|
||||
Status: "error",
|
||||
Code: 404,
|
||||
Message: "path not found: " + path,
|
||||
Status: "ok",
|
||||
Data: json.RawMessage(`{}`),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -33,8 +33,13 @@ func TestServerGetNotFound(t *testing.T) {
|
||||
tr := tree.New()
|
||||
resp := serverRoundTrip(t, tr, true, &Request{Method: "get", Path: "/nonexistent"})
|
||||
|
||||
if resp.Status != "error" || resp.Code != 404 {
|
||||
t.Fatalf("expected 404 error, got %+v", resp)
|
||||
// An absent subtree is "no data", not an error: ok + empty object,
|
||||
// so clients (statd, yangerctl) need no special-casing.
|
||||
if resp.Status != "ok" {
|
||||
t.Fatalf("expected ok, got %+v", resp)
|
||||
}
|
||||
if string(resp.Data) != "{}" {
|
||||
t.Fatalf("expected empty object data, got %s", resp.Data)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user